|
26233
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
git-commit Not Committed Yet, Git Blame Information
Not Committed Yet
Info: Downloading VS Code Server......
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26233
|
|
26234
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26234
|
|
26235
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26235
|
|
26236
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26236
|
|
26237
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
screep
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
git-commit Not Committed Yet, Git Blame Information
Not Committed Yet
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concis...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26237
|
|
26238
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26238
|
|
26239
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26239
|
|
26240
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26240
|
|
26241
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable....
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26241
|
|
26242
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26242
|
|
26243
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in
/volume1/screenpipe/pipes/
, but there's no code to actually load and run them —
consumers/summary.py
has its own hardcoded prompts instead.
Here's what I'll implement:
consumers/pipes.py
— dynamically loads pipe.md files and runs them via Claude (data injected as system message, pipe body as user prompt)
main.py
— two new endpoints:
GET /api/pipes
and
POST /api/pipes/{pipe_id}/run
cli.py
— a
pipe
command to run pipes from the terminal
Let me build it:
Bash
Check browser_urls signature
IN
cat /volume1/screenpipe/app/consumers/activity.py | grep "def browser_urls" -A 5
Copy code to clipboard
OUT
def browser_urls(
for_date: date | None = None,
app_name: str | None = None,
ts_from: str | None = None,
ts_to: str | None = None,
limit: int = 30,
Write
pipes.py
pipes.py
143 lines
"""Dynamic pipe loader and runner."""
import os
import re
from datetime import date
from pathlib import Path
from typing import Any
def _parse_frontmatter(text: str) -> tuple[dict, str]:
if not text.startswith("---"):
return {}, text
try:
end = text.index("---", 3)
except ValueError:
return {}, text
fm_text = text[3:end].strip()
body = text[end + 3:].strip()
meta: dict = {}
for line in fm_text.splitlines():
if ":" in line:
k, _, v = line.partition(":")
meta[k.strip()] = v.strip().strip('"')
return meta, body
def load_pipes(pipes_dir: Path) -> list[dict]:
if not pipes_dir.exists():
return []
pipes = []
for pipe_dir in sorted(pipes_dir.iterdir()):
if not pipe_dir.is_dir() or pipe_dir.name.startswith("."):
continue
pipe_md = pipe_dir / "pipe.md"
if not pipe_md.exists():
continue
text = pipe_md.read_text(encoding="utf-8")
meta, body = _parse_frontmatter(text)
if meta.get("enabled", "true").lower() == "false":
continue
body = re.sub(r"Read screenpipe skill first\.?\n?", "", body).strip()
pipes.append({
"id": pipe_dir.name,
"title": meta.get("title", pipe_dir.name),
"description": meta.get("description", ""),
"icon": meta.get("icon", ""),
"schedule": meta.get("schedule", "manual"),
"featured": meta.get("featured", "false").lower() == "true",
"prompt": body,
})
return pipes
def _build_system(d: date, stats: dict) -> str:
from consumers.activity import app_time, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
apps = app_time(d)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(d, limit=20)
url_lines = "\n".join(f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls)
ui_rows = ui_event_summary(d)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(d, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(d)
if len(audio) > 3000:
audio = audio[:3000]
return f"""You are analyzing screenpipe data — recordings of a person's computer activity.
## App usage (minutes per app):
{app_lines or '(no app data)'}
## Browser URLs visited:
{url_lines or '(no browser data)'}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_lines or '(no UI event data)'}
## Screen content (sampled every 5 minutes):
{ocr_lines or '(no screen data)'}
## Audio / speech:
{audio or '(no audio data)'}
Date: {d}
Total frames recorded: {stats['total_frames']}"""
def run_pipe(
pipe_id: str,
for_date: date | None = None,
api_key: str | None = None,
pipes_dir: Path | None = None,
) -> dict[str, Any]:
import anthropic
from consumers.activity import summary_stats
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {"title": "Error", "content": "ANTHROPIC_API_KEY not set.", "date": str(d)}
_pipes_dir = pipes_dir or Path(os.environ.get("PIPES_DIR", "/data/pipes"))
all_pipes = {p["id"]: p for p in load_pipes(_pipes_dir)}
if pipe_id not in all_pipes:
return {"title": "Error", "content": f"Pipe not found: {pipe_id}", "date": str(d)}
pipe = all_pipes[pipe_id]
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {"title": pipe["title"], "content": f"No screen data found for {d}.", "date": str(d)}
system = _build_system(d, stats)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
system=system,
messages=[{"role": "user", "content": pipe["prompt"]}],
)
return {
"title": pipe["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Now add the API endpoints to
main.py
:
Edit
main.py
main.py
Added 1 line
Edit
main.py
main.py
Added 1 line
Now add the pipe endpoints at the end of main.py, before the closing summary section:
Edit
main.py
main.py
Added 14 lines
Now add the CLI command to
cli.py
cli.py
:
Edit...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26243
|
|
26244
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26244
|
|
26245
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_f
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_f, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Plain Text
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 1, Col 1
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in
/volume1/screenpipe/pipes/
, but there's no code to actually load and run them —
consumers/summary.py
has its own hardcoded prompts instead.
Here's what I'll implement:
consumers/pipes.py
— dynamically loads pipe.md files and runs them via Claude (data injected as system message, pipe body as user prompt)
main.py
— two new endpoints:
GET /api/pipes
and
POST /api/pipes/{pipe_id}/run
cli.py
— a
pipe
command to run pipes from the terminal
Let me build it:
Bash
Check browser_urls signature
IN
cat /volume1/screenpipe/app/consumers/activity.py | grep "def browser_urls" -A 5
Copy code to clipboard
OUT
def browser_urls(
for_date: date | None = None,
app_name: str | None = None,
ts_from: str | None = None,
ts_to: str | None = None,
limit: int = 30,
Write
pipes.py
pipes.py
143 lines
"""Dynamic pipe loader and runner."""
import os
import re
from datetime import date
from pathlib import Path
from typing import Any
def _parse_frontmatter(text: str) -> tuple[dict, str]:
if not text.startswith("---"):
return {}, text
try:
end = text.index("---", 3)
except ValueError:
return {}, text
fm_text = text[3:end].strip()
body = text[end + 3:].strip()
meta: dict = {}
for line in fm_text.splitlines():
if ":" in line:
k, _, v = line.partition(":")
meta[k.strip()] = v.strip().strip('"')
return meta, body
def load_pipes(pipes_dir: Path) -> list[dict]:
if not pipes_dir.exists():
return []
pipes = []
for pipe_dir in sorted(pipes_dir.iterdir()):
if not pipe_dir.is_dir() or pipe_dir.name.startswith("."):
continue
pipe_md = pipe_dir / "pipe.md"
if not pipe_md.exists():
continue
text = pipe_md.read_text(encoding="utf-8")
meta, body = _parse_frontmatter(text)
if meta.get("enabled", "true").lower() == "false":
continue
body = re.sub(r"Read screenpipe skill first\.?\n?", "", body).strip()
pipes.append({
"id": pipe_dir.name,
"title": meta.get("title", pipe_dir.name),
"description": meta.get("description", ""),
"icon": meta.get("icon", ""),
"schedule": meta.get("schedule", "manual"),
"featured": meta.get("featured", "false").lower() == "true",
"prompt": body,
})
return pipes
def _build_system(d: date, stats: dict) -> str:
from consumers.activity import app_time, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
apps = app_time(d)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(d, limit=20)
url_lines = "\n".join(f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls)
ui_rows = ui_event_summary(d)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(d, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(d)
if len(audio) > 3000:
audio = audio[:3000]
return f"""You are analyzing screenpipe data — recordings of a person's computer activity.
## App usage (minutes per app):
{app_lines or '(no app data)'}
## Browser URLs visited:
{url_lines or '(no browser data)'}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_lines or '(no UI event data)'}
## Screen content (sampled every 5 minutes):
{ocr_lines or '(no screen data)'}
## Audio / speech:
{audio or '(no audio data)'}
Date: {d}
Total frames recorded: {stats['total_frames']}"""
def run_pipe(
pipe_id: str,
for_date: date | None = None,
api_key: str | None = None,
pipes_dir: Path | None = None,
) -> dict[str, Any]:
import anthropic
from consumers.activity import summary_stats
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {"title": "Error", "content": "ANTHROPIC_API_KEY not set.", "date": str(d)}
_pipes_dir = pipes_dir or Path(os.environ.get("PIPES_DIR", "/data/pipes"))
all_pipes = {p["id"]: p for p in load_pipes(_pipes_dir)}
if pipe_id not in all_pipes:
return {"title": "Error", "content": f"Pipe not found: {pipe_id}", "date": str(d)}
pipe = all_pipes[pipe_id]
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {"title": pipe["title"], "content": f"No screen data found for {d}.", "date": str(d)}
system = _build_system(d, stats)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
system=system,
messages=[{"role": "user", "content": pipe["prompt"]}],
)
return {
"title": pipe["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Now add the API endpoints to
main.py
:
Edit
main.py
main.py
Added 1 line
Edit
main.py
main.py
Added 1 line
Now add the pipe endpoints at the end of main.py, before the closing summary section:
Edit
main.py...
|
Code
|
screenpipe_f — screenpipe [SSH: nas]
|
NULL
|
26245
|
|
26246
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26246
|
|
26247
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26247
|
|
26248
|
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 214, Col 74
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in
/volume1/screenpipe/pipes/
, but there's no code to actually load and run them —
consumers/summary.py
has its own hardcoded prompts instead.
Here's what I'll implement:
consumers/pipes.py
— dynamically loads pipe.md files and runs them via Claude (data injected as system message, pipe body as user prompt)
main.py
— two new endpoints:
GET /api/pipes
and
POST /api/pipes/{pipe_id}/run
cli.py
— a
pipe
command to run pipes from the terminal
Let me build it:
Bash
Check browser_urls signature
IN
cat /volume1/screenpipe/app/consumers/activity.py | grep "def browser_urls" -A 5
Copy code to clipboard
OUT
def browser_urls(
for_date: date | None = None,
app_name: str | None = None,
ts_from: str | None = None,
ts_to: str | None = None,
limit: int = 30,
Write
pipes.py
pipes.py
143 lines
"""Dynamic pipe loader and runner."""
import os
import re
from datetime import date
from pathlib import Path
from typing import Any
def _parse_frontmatter(text: str) -> tuple[dict, str]:
if not text.startswith("---"):
return {}, text
try:
end = text.index("---", 3)
except ValueError:
return {}, text
fm_text = text[3:end].strip()
body = text[end + 3:].strip()
meta: dict = {}
for line in fm_text.splitlines():
if ":" in line:
k, _, v = line.partition(":")
meta[k.strip()] = v.strip().strip('"')
return meta, body
def load_pipes(pipes_dir: Path) -> list[dict]:
if not pipes_dir.exists():
return []
pipes = []
for pipe_dir in sorted(pipes_dir.iterdir()):
if not pipe_dir.is_dir() or pipe_dir.name.startswith("."):
continue
pipe_md = pipe_dir / "pipe.md"
if not pipe_md.exists():
continue
text = pipe_md.read_text(encoding="utf-8")
meta, body = _parse_frontmatter(text)
if meta.get("enabled", "true").lower() == "false":
continue
body = re.sub(r"Read screenpipe skill first\.?\n?", "", body).strip()
pipes.append({
"id": pipe_dir.name,
"title": meta.get("title", pipe_dir.name),
"description": meta.get("description", ""),
"icon": meta.get("icon", ""),
"schedule": meta.get("schedule", "manual"),
"featured": meta.get("featured", "false").lower() == "true",
"prompt": body,
})
return pipes
def _build_system(d: date, stats: dict) -> str:
from consumers.activity import app_time, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
apps = app_time(d)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(d, limit=20)
url_lines = "\n".join(f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls)
ui_rows = ui_event_summary(d)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(d, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(d)
if len(audio) > 3000:
audio = audio[:3000]
return f"""You are analyzing screenpipe data — recordings of a person's computer activity.
## App usage (minutes per app):
{app_lines or '(no app data)'}
## Browser URLs visited:
{url_lines or '(no browser data)'}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_lines or '(no UI event data)'}
## Screen content (sampled every 5 minutes):
{ocr_lines or '(no screen data)'}
## Audio / speech:
{audio or '(no audio data)'}
Date: {d}
Total frames recorded: {stats['total_frames']}"""
def run_pipe(
pipe_id: str,
for_date: date | None = None,
api_key: str | None = None,
pipes_dir: Path | None = None,
) -> dict[str, Any]:
import anthropic
from consumers.activity import summary_stats
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {"title": "Error", "content": "ANTHROPIC_API_KEY not set.", "date": str(d)}
_pipes_dir = pipes_dir or Path(os.environ.get("PIPES_DIR", "/data/pipes"))
all_pipes = {p["id"]: p for p in load_pipes(_pipes_dir)}
if pipe_id not in all_pipes:
return {"title": "Error", "content": f"Pipe not found: {pipe_id}", "date": str(d)}
pipe = all_pipes[pipe_id]
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {"title": pipe["title"], "content": f"No screen data found for {d}.", "date": str(d)}
system = _build_system(d, stats)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
system=system,
messages=[{"role": "user", "content": pipe["prompt"]}],
)
return {
"title": pipe["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Now add the API endpoints to
main.py
:
Edit
main.py
main.py
Added 1 line
Edit
main.py
main.py
Added 1 line
Now add the pipe endpoints at the end of main.py, before the closing summary section:
Edit
main.py
main.py
Added 14 lines
Now add the CLI command to
cli.py
cli.py
:
Edit
cli.py
cli.py
Added 40 lines
Done. Here's how to run pipes:
How to run pipes
How to run pipes
Via Docker (inside the running container):
Copy code to clipboard
docker exec -it screenpipe-app python cli.py pipe --list
docker exec -it screenpipe-app python cli.py pipe day-recap
docker exec -it screenpipe-app python cli.py pipe standup-update --date yesterday
Via the API
(once the container is running on port 8766):
Copy code to clipboard
# List pipes
curl http://localhost:8766/api/pipes
# Run a pipe
curl -X POST "http://localhost:8766/api/pipes/day-recap/run"
curl -X POST "http://localhost:8766/api/pipes/standup-update/run?d=2026-04-25"
Rebuild and restart
to pick up the changes:
Copy code to clipboard
cd /volume1/screenpipe/app
docker compose up --build -d
How it works:
Each
pipe.md
file is loaded dynamically — the frontmatter provides metadata and the body becomes the user prompt. Screenpipe data (app usage, browser URLs, OCR, audio) is injected as a Claude system message so the pipe prompt can reference it naturally. The "Read screenpipe skill first" line is stripped automatically.
The pipes directory inside Docker is
/data/pipes
(since
/volume1/screenpipe
→
/data
). You can override it with a
PIPES_DIR
env var if needed.
Message actions
pipe.md
pipe.md
where to place api key and can I use different keys
Thinking
Thinking
Bash
Read .env file
IN
cat /volume1/screenpipe/app/.env
Copy code to clipboard
OUT
[ENV_SECRET]
Where to place the key:
app/.env
app/.env
— replace
your_key_here
with your actual key:
Copy code to clipboard
[ENV_SECRET]
That file is loaded by
load_dotenv()
at startup and is excluded from git via
.gitignore
.
Can you use different keys per pipe?
Not currently — all pipes share the one key from
.env
. But you can add per-pipe key support by adding an
api_key
field to the pipe's frontmatter:
Copy code to clipboard
---
title: Meeting Summary
api_key_env: ANTHROPIC_KEY_MEETINGS
---
Then in
consumers/pipes.py
consumers/pipes.py
, read it in
_parse_frontmatter
and pass it through
run_pipe
. Want me to add that?
Message actions
pipe.md
pipe.md
can I use mistral or other llm? or is is build for antrophic only
Thinking
Thinking
Currently it's Anthropic-only — the code calls the
anthropic
SDK directly in both
consumers/pipes.py
consumers/pipes.py
and
consumers/summary.py
consumers/summary.py
.
Adding other providers is straightforward since Mistral, Ollama, OpenRouter, Groq, and most modern LLMs expose an OpenAI-compatible API. The cleanest approach: add the
openai
package and let you configure the provider via
.env
:
Copy code to clipboard
# Anthropic (default)
[ENV_SECRET]
# OR: any OpenAI-compatible provider
LLM_PROVIDER=openai-compatible
LLM_BASE_URL=https://api.mistral.ai/v1
[ENV_SECRET]
LLM_MODEL=mistral-small-latest
This would cover Mistral, Ollama (...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26248
|
|
26249
|
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 200, Col 87
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26249
|
|
26250
|
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 200, Col 87
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in
/volume1/screenpipe/pipes/
, but there's no code to actually load and run them —
consumers/summary.py
has its own hardcoded prompts instead.
Here's what I'll implement:
consumers/pipes.py
— dynamically loads pipe.md files and runs them via Claude (data injected as system message, pipe body as user prompt)
main.py
— two new endpoints:
GET /api/pipes
and
POST /api/pipes/{pipe_id}/run
cli.py
— a
pipe
command to run pipes from the terminal
Let me build it:
Bash
Check browser_urls signature
IN
cat /volume1/screenpipe/app/consumers/activity.py | grep "def browser_urls" -A 5
Copy code to clipboard
OUT
def browser_urls(
for_date: date | None = None,
app_name: str | None = None,
ts_from: str | None = None,
ts_to: str | None = None,
limit: int = 30,
Write
pipes.py
pipes.py
143 lines
"""Dynamic pipe loader and runner."""
import os
import re
from datetime import date
from pathlib import Path
from typing import Any
def _parse_frontmatter(text: str) -> tuple[dict, str]:
if not text.startswith("---"):
return {}, text
try:
end = text.index("---", 3)
except ValueError:
return {}, text
fm_text = text[3:end].strip()
body = text[end + 3:].strip()
meta: dict = {}
for line in fm_text.splitlines():
if ":" in line:
k, _, v = line.partition(":")
meta[k.strip()] = v.strip().strip('"')
return meta, body
def load_pipes(pipes_dir: Path) -> list[dict]:
if not pipes_dir.exists():
return []
pipes = []
for pipe_dir in sorted(pipes_dir.iterdir()):
if not pipe_dir.is_dir() or pipe_dir.name.startswith("."):
continue
pipe_md = pipe_dir / "pipe.md"
if not pipe_md.exists():
continue
text = pipe_md.read_text(encoding="utf-8")
meta, body = _parse_frontmatter(text)
if meta.get("enabled", "true").lower() == "false":
continue
body = re.sub(r"Read screenpipe skill first\.?\n?", "", body).strip()
pipes.append({
"id": pipe_dir.name,
"title": meta.get("title", pipe_dir.name),
"description": meta.get("description", ""),
"icon": meta.get("icon", ""),
"schedule": meta.get("schedule", "manual"),
"featured": meta.get("featured", "false").lower() == "true",
"prompt": body,
})
return pipes
def _build_system(d: date, stats: dict) -> str:
from consumers.activity import app_time, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
apps = app_time(d)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(d, limit=20)
url_lines = "\n".join(f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls)
ui_rows = ui_event_summary(d)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(d, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(d)
if len(audio) > 3000:
audio = audio[:3000]
return f"""You are analyzing screenpipe data — recordings of a person's computer activity.
## App usage (minutes per app):
{app_lines or '(no app data)'}
## Browser URLs visited:
{url_lines or '(no browser data)'}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_lines or '(no UI event data)'}
## Screen content (sampled every 5 minutes):
{ocr_lines or '(no screen data)'}
## Audio / speech:
{audio or '(no audio data)'}
Date: {d}
Total frames recorded: {stats['total_frames']}"""
def run_pipe(
pipe_id: str,
for_date: date | None = None,
api_key: str | None = None,
pipes_dir: Path | None = None,
) -> dict[str, Any]:
import anthropic
from consumers.activity import summary_stats
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {"title": "Error", "content": "ANTHROPIC_API_KEY not set.", "date": str(d)}
_pipes_dir = pipes_dir or Path(os.environ.get("PIPES_DIR", "/data/pipes"))
all_pipes = {p["id"]: p for p in load_pipes(_pipes_dir)}
if pipe_id not in all_pipes:
return {"title": "Error", "content": f"Pipe not found: {pipe_id}", "date": str(d)}
pipe = all_pipes[pipe_id]
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {"title": pipe["title"], "content": f"No screen data found for {d}.", "date": str(d)}
system = _build_system(d, stats)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
system=system,
messages=[{"role": "user", "content": pipe["prompt"]}],
)
return {
"title": pipe["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Now add the API endpoints to
main.py
:
Edit
main.py
main.py
Added 1 line
Edit
main.py
main.py
Added 1 line
Now add the pipe endpoints at the end of main.py, before the closing summary section:
Edit
main.py
main.py
Added 14 lines
Now add the CLI command to
cli.py
cli.py
:
Edit
cli.py
cli.py
Added 40 lines
Done. Here's how to run pipes:
How to run pipes
How to run pipes
Via Docker (inside the running container):
Copy code to clipboard
docker exec -it screenpipe-app python cli.py pipe --list
docker exec -it screenpipe-app python cli.py pipe day-recap
docker exec -it screenpipe-app python cli.py pipe standup-update --date yesterday
Via the API...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26250
|
|
26251
|
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 25, Col 58
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26251
|
|
26252
|
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Explorer (⇧⌘E) - 2 unsaved files
2
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 25, Col 58
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in
/volume1/screenpipe/pipes/
, but there's no code to actually load and run them —
consumers/summary.py
has its own hardcoded prompts instead.
Here's what I'll implement:
consumers/pipes.py
— dynamically loads pipe.md files and runs them via Claude (data injected as system message, pipe body as user prompt)
main.py
— two new endpoints:
GET /api/pipes
and
POST /api/pipes/{pipe_id}/run
cli.py
— a
pipe...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26252
|
|
26288
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26288
|
|
26289
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 25, Col 58
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26289
|
|
26290
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 32, Col 73
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26290
|
|
26291
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
#!/bin/bash
# screenpipe_fts_migrate.sh
# One-shot migration of the screenpipe NAS archive DB to the new schema:
# - adds install_id column to every synced base table
# - creates the _installs registry
# - rebuilds all four FTS tables as contentless with install_id + source_id
#
# This is OPTIONAL. screenpipe_sync.sh performs the same migration inline on
# its first run. The point of running this separately is SPEED: SQLite over
# SMB is slow due to fsync semantics, and the FTS rebuild reads every row
# of every base table. Running the rebuild locally on the NAS over SSH is
# typically 5-10x faster.
#
# Idempotent — safe to re-run. Detects the new schema and exits if already migrated.
#
# Usage
# -----
# On the NAS via SSH (recommended for archives > 1 GB):
# ssh Adm1n@[IP_ADDRESS]
# # copy this script over first, then:
# ./screenpipe_fts_migrate.sh /volume1/Test/screenpipe/archive.db
#
# On Mac (works but slower):
# ./screenpipe_fts_migrate.sh /Volumes/screenpipe/archive.db
# # or with no arg to use the default Mac mount path:
# ./screenpipe_fts_migrate.sh
set -euo pipefail
NAS_DB="${1:-/Volumes/screenpipe/archive.db}"
VISION_TABLES=(video_chunks frames elements ocr_text ui_events meetings)
AUDIO_TABLES=(speakers speaker_embeddings audio_chunks audio_transcriptions audio_tags)
SHARED_TABLES=(tags vision_tags)
ALL_SYNC_TABLES=("${VISION_TABLES[@]}" "${AUDIO_TABLES[@]}" "${SHARED_TABLES[@]}")
FTS_TABLES=(frames_fts elements_fts ui_events_fts audio_transcriptions_fts)
# ─── HELPERS ──────────────────────────────────────────────────────────────────
table_exists() {
local count
count=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$1';")
[ "$count" -gt 0 ]
}
step() {
printf "\n▶ %s\n" "$*"
}
run_with_timer() {
local label="$1" sql="$2"
local start
start=$(date +%s)
printf " %-44s " "$label"
if sqlite3 "$NAS_DB" "$sql" > /dev/null 2>&1; then
local dur=$(( $(date +%s) - start ))
printf "✓ %dm%02ds\n" "$(( dur / 60 ))" "$(( dur % 60 ))"
else
printf "✗ FAILED\n"
sqlite3 "$NAS_DB" "$sql" # re-run to surface the error
exit 1
fi
}
# ─── PREFLIGHT ────────────────────────────────────────────────────────────────
[ -f "$NAS_DB" ] || { echo "ERROR: $NAS_DB not found"; exit 1; }
echo "================================================"
echo "Screenpipe FTS migration"
echo "DB: $NAS_DB"
echo "Size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
# ─── STEP 1: install registry ─────────────────────────────────────────────────
step "Creating install registry"
run_with_timer "_installs table" "
CREATE TABLE IF NOT EXISTS _installs (
install_id TEXT PRIMARY KEY,
install_seq INTEGER NOT NULL UNIQUE,
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
last_seen TEXT NOT NULL DEFAULT (datetime('now'))
);
"
# ─── STEP 2: install_id on base tables ────────────────────────────────────────
step "Adding install_id to base tables"
LEGACY_TAG="legacy-$(date +%Y%m%d)"
LEGACY_USED=false
for tbl in "${ALL_SYNC_TABLES[@]}"; do
if ! table_exists "$tbl"; then
printf " %-44s (table not present, skipping)\n" "$tbl"
continue
fi
HAS_COL=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM pragma_table_info('$tbl') WHERE name='install_id';")
if [ "$HAS_COL" = "0" ]; then
ROW_COUNT=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM $tbl;")
printf " %-44s adding (backfill %s rows)\n" "$tbl" "$ROW_COUNT"
sqlite3 "$NAS_DB" "ALTER TABLE $tbl ADD COLUMN install_id TEXT;"
sqlite3 "$NAS_DB" "UPDATE $tbl SET install_id = '$LEGACY_TAG' WHERE install_id IS NULL;"
[ "$ROW_COUNT" -gt "0" ] && LEGACY_USED=true
else
printf " %-44s already present\n" "$tbl"
fi
if [ "$tbl" = "vision_tags" ]; then
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_vision_tags_install_pk ON vision_tags(install_id, vision_id, tag_id);"
else
sqlite3 "$NAS_DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx_${tbl}_install_pk ON ${tbl}(install_id, id);"
fi
done
if [ "$LEGACY_USED" = true ]; then
sqlite3 "$NAS_DB" "
INSERT OR IGNORE INTO _installs(install_id, install_seq, first_seen, last_seen)
VALUES ('$LEGACY_TAG', (SELECT COALESCE(MAX(install_seq),0)+1 FROM _installs), 'pre-migration', 'pre-migration');
"
fi
# ─── STEP 3: detect old FTS ───────────────────────────────────────────────────
OLD_FTS_DETECTED=false
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
SCHEMA_SQL=$(sqlite3 "$NAS_DB" "SELECT sql FROM sqlite_master WHERE name='$fts';")
if echo "$SCHEMA_SQL" | grep -q "content=" || ! echo "$SCHEMA_SQL" | grep -q "install_id"; then
OLD_FTS_DETECTED=true
break
fi
fi
done
if [ "$OLD_FTS_DETECTED" = false ]; then
echo ""
echo "FTS tables already on the new schema — nothing to rebuild."
echo "Migration complete."
exit 0
fi
# ─── STEP 4: rebuild FTS tables ───────────────────────────────────────────────
step "Rebuilding FTS tables (this is the slow part)"
for fts in "${FTS_TABLES[@]}"; do
if table_exists "$fts"; then
run_with_timer "drop old $fts" "DROP TABLE $fts;"
fi
done
run_with_timer "create frames_fts" "
CREATE VIRTUAL TABLE frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create elements_fts" "
CREATE VIRTUAL TABLE elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create ui_events_fts" "
CREATE VIRTUAL TABLE ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
run_with_timer "create audio_transcriptions_fts" "
CREATE VIRTUAL TABLE audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
"
# Populate from base tables. The slow operations live here.
if table_exists "frames"; then
run_with_timer "populate frames_fts" "
INSERT INTO frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM frames WHERE full_text IS NOT NULL AND full_text != '';
"
fi
if table_exists "elements"; then
run_with_timer "populate elements_fts" "
INSERT INTO elements_fts(text, role, install_id, source_id, frame_id)
SELECT text, role, install_id, id, frame_id
FROM elements WHERE text IS NOT NULL;
"
fi
if table_exists "ui_events"; then
run_with_timer "populate ui_events_fts" "
INSERT INTO ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM ui_events WHERE text_content IS NOT NULL;
"
fi
if table_exists "audio_transcriptions"; then
run_with_timer "populate audio_transcriptions_fts" "
INSERT INTO audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT transcription, COALESCE(device,''), speaker_id, install_id, id
FROM audio_transcriptions WHERE transcription IS NOT NULL AND transcription != '';
"
fi
echo ""
echo "================================================"
echo "Migration complete."
echo "Final DB size: $(du -sh "$NAS_DB" | cut -f1)"
echo "================================================"
echo ""
echo "Sanity-check queries you can run:"
echo " sqlite3 $NAS_DB 'SELECT * FROM _installs;'"
echo " sqlite3 $NAS_DB \"SELECT sql FROM sqlite_master WHERE name='frames_fts';\""
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM frames_fts;'"
echo " sqlite3 $NAS_DB 'SELECT COUNT(*) FROM audio_transcriptions_fts;'"
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 4
Ln 26, Col 34
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
description: "What you did, what's next, and any blockers"
icon: "🏢"
featured: true
---
Based on my recordings from the last 24 hours, generate a standup update. Use limit=10 per search, max 3 searches total.
Read screenpipe skill first.
Use this exact format:
## Yesterday
- What I worked on (name specific projects, files, tools, PRs)
## Today
- What I will work on next (based on unfinished tasks and recent activity)
## Blockers
- Issues I hit — errors, slow builds, waiting on someone
- If no blockers, write "None"
Keep it under 150 words. Copy-paste ready for a team standup.
=== /volume1/screenpipe/pipes/time-breakdown/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Time Breakdown
description: "Where your time went — by app, project, and category"
icon: "⏱"
featured: false
---
Analyze my app usage from today (last 12 hours). Use limit=10 per search, max 4 searches. Prefer /raw_sql with COUNT/GROUP BY queries.
Read screenpipe skill first.
Use this exact format with durations and percentages:
## By Application
- List each app with duration and percentage, sorted by time (e.g. "VS Code: 2h 15min (28%)")
## By Category
- Group into: coding, meetings, browsing, writing, communication, other
- Show hours and percentage per category
## By Project
- Group related activities by project/topic. Name specific repos or tasks.
## Productivity Score
- Calculate: focused_work_hours / total_hours as a percentage
- Focused = coding + writing. Unfocused = browsing + switching.
End with: "**Suggestion:** [one specific change to improve tomorrow's productivity]"
=== /volume1/screenpipe/pipes/video-export/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Export Video Clip
description: "Create a video of your recent screen activity"
icon: "🎬"
featured: false
---
Export a video of my screen activity from the last 5 minutes.
Read screenpipe skill first.
Use the POST /frames/export endpoint with the time range and fps=1.0. Then show me the exported video file path as an inline code block so I can watch it.
If the export is large, suggest a lower fps or shorter time range.
Thinking
Thinking
Now I have a clear picture. The pipes are markdown prompt templates in
/volume1/screenpipe/pipes/
, but there's no code to actually load and run them —
consumers/summary.py
has its own hardcoded prompts instead.
Here's what I'll implement:
consumers/pipes.py
— dynamically loads pipe.md files and runs them via Claude (data injected as system message, pipe body as user prompt)
main.py
— two new endpoints:
GET /api/pipes
and
POST /api/pipes/{pipe_id}/run
cli.py
— a
pipe
command to run pipes from the terminal
Let me build it:
Bash
Check browser_urls signature
IN
cat /volume1/screenpipe/app/consumers/activity.py | grep "def browser_urls" -A 5
Copy code to clipboard
OUT
def browser_urls(
for_date: date | None = None,
app_name: str | None = None,
ts_from: str | None = None,
ts_to: str | None = None,
limit: int = 30,
Write
pipes.py
pipes.py
143 lines
"""Dynamic pipe loader and runner."""
import os
import re
from datetime import date
from pathlib import Path
from typing import Any
def _parse_frontmatter(text: str) -> tuple[dict, str]:
if not text.startswith("---"):
return {}, text
try:
end = text.index("---", 3)
except ValueError:
return {}, text
fm_text = text[3:end].strip()
body = text[end + 3:].strip()
meta: dict = {}
for line in fm_text.splitlines():
if ":" in line:
k, _, v = line.partition(":")
meta[k.strip()] = v.strip().strip('"')
return meta, body
def load_pipes(pipes_dir: Path) -> list[dict]:
if not pipes_dir.exists():
return []
pipes = []
for pipe_dir in sorted(pipes_dir.iterdir()):
if not pipe_dir.is_dir() or pipe_dir.name.startswith("."):
continue
pipe_md = pipe_dir / "pipe.md"
if not pipe_md.exists():
continue
text = pipe_md.read_text(encoding="utf-8")
meta, body = _parse_frontmatter(text)
if meta.get("enabled", "true").lower() == "false":
continue
body = re.sub(r"Read screenpipe skill first\.?\n?", "", body).strip()
pipes.append({
"id": pipe_dir.name,
"title": meta.get("title", pipe_dir.name),
"description": meta.get("description", ""),
"icon": meta.get("icon", ""),
"schedule": meta.get("schedule", "manual"),
"featured": meta.get("featured", "false").lower() == "true",
"prompt": body,
})
return pipes
def _build_system(d: date, stats: dict) -> str:
from consumers.activity import app_time, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
apps = app_time(d)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(d, limit=20)
url_lines = "\n".join(f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls)
ui_rows = ui_event_summary(d)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(d, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(d)
if len(audio) > 3000:
audio = audio[:3000]
return f"""You are analyzing screenpipe data — recordings of a person's computer activity.
## App usage (minutes per app):
{app_lines or '(no app data)'}
## Browser URLs visited:
{url_lines or '(no browser data)'}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_lines or '(no UI event data)'}
## Screen content (sampled every 5 minutes):
{ocr_lines or '(no screen data)'}
## Audio / speech:
{audio or '(no audio data)'}
Date: {d}
Total frames recorded: {stats['total_frames']}"""
def run_pipe(
pipe_id: str,
for_date: date | None = None,
api_key: str | None = None,
pipes_dir: Path | None = None,
) -> dict[str, Any]:
import anthropic
from consumers.activity import summary_stats
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {"title": "Error", "content": "ANTHROPIC_API_KEY not set.", "date": str(d)}
_pipes_dir = pipes_dir or Path(os.environ.get("PIPES_DIR", "/data/pipes"))
all_pipes = {p["id"]: p for p in load_pipes(_pipes_dir)}
if pipe_id not in all_pipes:
return {"title": "Error", "content": f"Pipe not found: {pipe_id}", "date": str(d)}
pipe = all_pipes[pipe_id]
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {"title": pipe["title"], "content": f"No screen data found for {d}.", "date": str(d)}
system = _build_system(d, stats)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
system=system,
messages=[{"role": "user", "content": pipe["prompt"]}],
)
return {
"title": pipe["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Now add the API endpoints to
main.py
:
Edit
main.py
main.py
Added 1 line
Edit
main.py
main.py
Added 1 line
Now add the pipe endpoints at the end of main.py, before the closing summary section:
Edit
main.py
main.py
Added 14 lines
Now add the CLI command to
cli.py
cli.py
:
Edit
cli.py
cli.py
Added 40 lines
Done. Here's how to run pipes:
How to run pipes
How to run pipes
Via Docker (inside the running container):
Copy code to clipboard
docker exec -it screenpipe-app python cli.py pipe --list
docker exec -it screenpipe-app python cli.py pipe day-recap
docker exec -it screenpipe-app python cli.py pipe standup-update --date yesterday
Via the API
(once the container is running on port 8766):
Copy code to clipboard
# List pipes
curl http://localhost:8766/api/pipes
# Run a pipe
curl -X POST "http://localhost:8766/api/pipes/day-recap/run"
curl -X POST "http://localhost:8766/api/pipes/standup-update/run?d=2026-04-25"
Rebuild and restart
to pick up the changes:
Copy code to clipboard
cd /volume1/screenpipe/app
docker compose up --build -d
How it works:
Each...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26291
|
|
26297
|
Explorer (⇧⌘E) - 1 unsaved file
iTerm2ShellEditV Explorer (⇧⌘E) - 1 unsaved file
iTerm2ShellEditViewSessionScriptsProfilesWindowHelpRetro - Platform - in 1h 41 m100% <78• Tue 12 May 15:19:08DOCKERDOCKER (-zsh)STAGE (ssh)₴81DEV (-zsh)O $2APP (-zsh)883ec2-user@ip-10-30-129-.84T2PROD (-zsh)181screenpipe*kibanaasticsearch"{"type" : "log""@timestamp": "2026-05-11T19:54:53Z","tags" : ["warning","el,"data"], "pid" :7,'"message": "Unabletorevive connection: [URL_WITH_CREDENTIALS] : "2026-05-11T19:54:53Z",asticsearch", "data"],"pid":7,"message": "No livingconnections"}["warning".,"elkibanaI {"type" : "log", "@timestamp" : "2026-05-11T19:54:53Z"ugins""licensing"], "pid" :7,"message" : "License informationasticsearch due to Error: No Livingconnectionskibana1 {"type" : "log","@timestamp": "2026-05-11T19:54:54Z","tags" : ["error"ticsearch", "data"], "pid":7, "message" : "[ConnectionError]: getaddrinfo ENOTFOUND elasticsearch elasticsearch: 9200"}kibana1 {"type" : "log","@timestamp": "2026-05-11T19:54:54Z", "tags" : ["warning", "elasticsearch", "data"], "pid" :7,"message":"Unable to reviveconnection: [URL_WITH_CREDENTIALS] "2026-05-11T19:54:54Z","tags" : ["warning", "elasticsearch", "data"],"pid":7,"message"• "No livingconnections"}kibana1 {"type": "log","@timestamp": "2026-05-11T19:54:54Z""tags" : ["error", "plugins", "taskManager""taskManager"], "pid":7, "message": "Failed to poll for work: Error: NoLiving connections"}kibana1 {"type": "log", "@timestamp": "2026-05-11T19:54:572", "tags" : ["error", "elasticsearch".,"data"], "pid" :7, "message" :"[ConnectionError]: getaddrinfo ENOTFOUND elasticsearch elasticsearch:9200*}kibana1 {"type" : "Log","@timestamp" : "2026-05-11T19:54:57Z","tags" : ["warning","elasticsearch", "data"], "pid" :7, "message": "Unable to revive connection: [URL_WITH_CREDENTIALS] : "2026-05-11T19:54:57Z", "tags" : ["warning", "elasticsearch", "data"], "pid" :7, "message": "No living connections"}kibanaI {"type" : "log", "@timestamp" : "2026-05-11T19:54:57Z", "tags" : ["error","plugins", "taskManager", "taskManager"], "pid" :7, "message" : "Failed to pollfor work: Error: NoLiving connections"}kibanaI {"type" : "log", "@timestamp" : "2026-05-11T19:54:59Z","tags" : ["error", "elasticsearch", "data"], "pid" :7, "message" : "[ConnectionError]: getaddrinfo ENOTFOUND elasticsearch elasticsearch:9200"}1 {"type" : "log","@timestamp": "2026-05-11T19:55: 00Z""tags": ["warning"asticsearch", "data"], "pid" :7, "message": "Unable to revive connection: [URL_WITH_CREDENTIALS] : "2026-05-11T19:55 :00Z", "tags" : ["warning", "elasticsearch", "data"], "pid" :7, "message": "No living connections"}1 {"type": "log", "@timestamp" : "2026-05-11T19:55:00Z","tags" : ["error", "plug, "taskManager",, "taskManager"], "pid" :7, "message": "Failed to poll for work: Error: NoLiving connections"}unexpected EOFkas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/infrastructure/dev/docker (develop) $-zshX5O 886-zsh*** System restart required ***Last login: Thu May7 08:01:13 2026 from 212.5.153.87lukas@jiminny-prod-bastion:~$lukas@jiminny-prod-bastion:~$ client_loop: send disconnect: Broken pipeukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~ $ ||XIT3 EU (ssh)New release '24.04.4 LTS' available.Run'do-release-upgrade' to upgrade to it.*** System restart required ***Last login: Wed Apr 22 08:09:46 2026 from 212.5.153.87lukas@jiminny-eu-bastion:~$ 0T4STAGE (ssh)Run 'do-release-upgrade' to upgrade to it.System restart required ***Last login: Thu May7 11:01:47 2026 from 212.5.153.87bastion:-$QA (-zsh)Poetry could not find a pyproject.toml file in /Users/lukas or its parentsPoetry could not find a pyproject.toml file in /Users/lukas or its parentsT6FE (-zsh)Poetry could not find a pyproject.toml file in /Users/lukas or its parentsPRODSTAGEFRONTENDPoetry could not find a pyproject.toml file in /Users/lukas or its parentsLukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~ $ |17 EXT (-zsh)Poetry could not find a pyproject.toml file in /Users/lukas or its parentsPoetry could not find a pyproject.toml file in /Users/lukas or its parentsukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~ $ lEXTENSION...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26297
|
|
26298
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
VIeWWindowmeltEXPLORERV SCREENPIPE [SSH: NAS]• #recycle› app› logs• gitignore() app_settings.jsonE archive.dlE archive.db-bak= db.saliteE db.salite-shm= db.salite-wal$ screenpipe_fts_migrate.shS screenoioe sunc uodated.sh$ screenpine svnc.sh= screennine.dbOUTIINE> TIMELINEes apo_settinas.ison*SSH: nas i&master ( @0A0 (g)1screenpipe sync.shMs screenpipe tts migrate.sh Xscreenpipe sunc updated.shupipe.md$ screenpipe_fts_migrate.shfor tbl in105EEEEБEВ123125"STALL SYNC TABLES a": doelsesqlite3 "SNAS DB" "CREATE UNIQUE INDEX IF NOT EXISTS idx ${tbl} install pk ON S{tbl}(install id, id):"I "SLEGACY USED" = true : thensOUite? "SNAS DR""INSERT OR IGNORE INTO installs(install id, install_ seq, first seen, last_ seen)VALUES ('$LEGACY_ TAG', (SELECT COALESCE(MAX(install_ seq),0)+1 FROM installs), 'pre-migration', 'pre-migration');STEP 3: detect old FTStor FTSLES(@J}"; docdole exists oris, chetSCHEMA SQL=$(sqlite3 "$NAS DB" "SELECT sql FROM sqlite master WHERE name='$fts';")iT echo "SSChcMAsUL" orep -o "contene" echo"SSCHEMA SUL"-q "install id"; thenOLD FTs DETECTED=truebreakif [ "SOLD_FTS_DETECTED" = false ]; thenecho "g rabtes olreat, n the ner schens - nothing to rebuftl,.STEP 4:rebuild FTS tablesstep "Rebuilding FTS tables (this is the slow part)'for fts in "S{FTS TABLES[@]}": ddit table exists "Stts" therun with timer "droo old Sfts" "DROP TABLE SttS:"run with timer #create frames f+cl "GRFATE VTPTLIAL TARIE framec f+c IISTNG f+c5/window_name, browser_url,OUTPUTDEBUG CONSOLEPORTS (1.[15:12:54) Getting Manifest…ing extensiepinned: talse,productVersion: { version: '1.119.0', date: '2026-05-05T11:23:50-07:00' }.115:12:54.845operation: 3,isAppLicationScoped: false."/home/Admin/.vscode-server/extensions/extensions.ison'115.12-591 Extension simnature verification result for anthronic claude-code. Success Internal Code. 0. Execntede tme Duratione 12[15:13:00] Extracted extension to [URL_WITH_CREDENTIALS] /volume1/Test/screenpipe/archive.db /volume1/Test/screeIfanvthing goes sidewavs vou restore from this and re-run the oldscript.2. Pause the cron iob to avoid a race with the migration:crontab -e# comment out the screenpipe sync.sh line3. Pick a migration path.Path A - tast recommended itarchive is more than ~1 GB. runithe migration on the NAS over SSHYou're out of extra usage • Your limit resets at 7:20 PMBuy moreWrite a message…Opus 47 AdaptivevClaudo ic Aland can make mictakec Plosce double-chockr•ketro - Platomm • In 1h 41m100% 2• Tue 12 May 15:19:08screenplpe res migrate ohcopyspeaker 1d UNINDEXED, 1nstall 1d UNINDEXED, SOUrce 10 UNINDEXED175176if table exists "frames": thenrun_with_timer "populate frames_fts""INSERT INTO frames ftsful text, app name, window name. browser urinstalb id. source id)SELECT fub text. app name. window name, browser uni, instab id. idFROM frames WHERE full text IS NOT NULL AND fuil text 1e 11.if table exists "elements". thenrun with timer "populate elements fts"INSERT INTO elements fts(text, role, install id, source id, frame idSELECT text, role, install id, id, frame idGROM elomonte WHERE tovt TC NOT NulI•iT caole exists "ul events, chenrun with timer "populate vi events fts" "INSERT INTO U1 events Ttstext content, app name, window title, element name, instal 1d, source 1d)SELECT text content, app name, window title, element name, install id,FROM u1 events WHERE text content is Not NULL,if table exists "audio transcriptions": then"populate audio transcriptions fts""INSERT INTO audio transcriptions fts(transcription. device, speaker id install id source 1d)SELECT transcription, COALESCE(device,''), speaker_id, install_id, idFROM audio transcrintions WHERE transcrintion IS NOT NULL AND transcriotion le 11.207echo "Migration complete.""Final DB size: $(du -sh "$NAS_DB" | cut -f1)"echo "Sanity-check queries you can run:"echo "sqlite3 $NAS DB 'SELECT * FROM installs:'"echo"sglite3 $NAS DB \"SELECT sql FROM sglite master WHERE name='frameochn nsalite3 $NAS DB 'SELECT COUNT(*) FROM frames fts:'*echo"salite3 $NAS DB 'SELECT COUNT(*) FROM audio transcriptions fts:'...
|
Code
|
screenpipe_fts_migrate.sh — screenpipe [SSH: nas]
|
NULL
|
26298
|
|
26299
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actiona...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26299
|
|
26617
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26617
|
|
26618
|
Explorer (⇧⌘E) - 1 unsaved file
SlackFileEditViewG Explorer (⇧⌘E) - 1 unsaved file
SlackFileEditViewGoHistoryWindowHelpRetro - Platform • in 1 h 12 msshDOCKER• 81DEV (-zsh)О ₴2APP (-zsh)• *[EMAIL]@Lukas-Kovaliks-MacBook-Pro-Jiminny~/.screenpipe/data $ cd ..[EMAIL] $ nasAdm1n@DXP4800PLUS-B5F8: ~$cd/volumel/screenpipe/Adm1n@DXP4800PLUS-B5F8:/volume1/screenpipes 1ltotal26Gdrwxrwxrwx+1rootroot410 May1215:15drwxr-xr-xrootroot450 Apr2519:39drwxrwxrwx+1Adminadmin202 Apr2620:10drwxrwxrwx+1Adminadmin298 May1013:46drwxrwxrwx+Adminadmin144 May09:41drwxrwxrwx+1Admin admin70 May1013:47drwxrwxrwx+1Adminadmin164 Apr1116:51drwxrwxrwx+1rootroot5.1KMay1120:55-rwxrwxrwx+1rootroot31Apr1817:42app_settings.json1Adminadmin13G May1120:55archive.db-rwxrwxrwx+1Adminadmin11G May10-rwxrwxrwx+Adm1n admin 3.5G May1112:31archive.db-bak20:15db.sqlite-rwxrwxrwx+1Admin admin32K May1205:48db.sqlite-shm-rwxrwxrwx+ 1Admin admin0 Apr 26 17:17db.sqlite-wal1Admin admin11K May 12 09:09.DS_Store-rwxrwxrwx+ 1 Admin admin219 Apr24 19:33•gitignore-rwxrwxrWx+1 Admin admin0 Apr1317:21screenpipe.db-rwxrwxrwx+1 Admin admin 8.4K May12 15:15screenpipe_fts_migrate.sh-rwxrwxrwx+ 1 Admin admin32K May 11 20:48screenpipe_sync.sh-rwxrwxrwx+ 1 Admin admin20K May 10 13:06screenpipe_sync_updated.shAdm1n@DXP4800PLUS-B5F8:/volume1/screenpipe$ cp archive.dbarchive.db.bak-pre-installidAdm1n@DXP4800PLUS-B5F8:/volume1/screenpipes ./screenpipe_fts_migrate.sh archive.dbScreenpipe FTS migrationDB:archive.dbSize: 13G• ×4-zsh• 285screenpipe"O 886ssh100% <78•Tue 12 May 15:48:1518187-zsh• *8+• Creating install registry_installs table• Om01s• Adding install_id to base tablesvideo_chunksalready presentError: stepping, UNIQUEconstraintfailed: video_chunks.install_id, video_chunks.id (19)Adm1n@DXP4800PLUS-B5F8:/volume1/screenpipes sqlite3 archive.db "SELECT * FROM_installs;"Adm1neDXP4800PLUS-B5F8:/volume1/screenpipes sqlite3 archive.db "SELECT install_id, COUNT(*) FROM frames GROUP BY install_id;"Error: in prepare, no such column: install_idSELECT install_id,COUNT(*) FROM frames GROUP BY install_id;^_-- error hereAdm1n@DXP4800PLUS-B5F8:/volume1/screenpipes |...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26618
|
|
26619
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follo...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26619
|
|
26620
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
Problems (⇧⌘M)
PROBLEMS
Output (⇧⌘U)
OUTPUT
Debug Console (⇧⌘Y)
DEBUG CONSOLE
Terminal (⌃`)
TERMINAL
Ports - 1 forwarded port
PORTS
1
Remote - SSH - Output...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26620
|
|
26621
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26621
|
|
26622
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26622
|
|
26623
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26623
|
|
26624
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26624
|
|
26625
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26625
|
|
26626
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26626
|
|
26635
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26635
|
|
26643
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26643
|
|
26644
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26644
|
|
26645
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26645
|
|
26646
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26646
|
|
26647
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26647
|
|
26648
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26648
|
|
26649
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26649
|
|
26650
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26650
|
|
26651
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26651
|
|
26652
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26652
|
|
26653
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26653
|
|
26654
|
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Explorer (⇧⌘E) - 1 unsaved file
1
Search (⇧⌘F)
Source Control (⌃⇧G) - 11 pending changes
11
Run and Debug (⇧⌘D)
Remote Explorer
Extensions (⇧⌘X) - 2 require update, 1 requires restart
3
Claude Code
Containers
EXPLORER
EXPLORER
Explorer Section: screenpipe [SSH: nas]
Explorer Section: screenpipe [SSH: nas]
SCREENPIPE [SSH: NAS]
#recycle
app
data
logs
pipes
.gitignore
app_settings.json
archive.db
archive.db-bak
U
archive.db.bak-pre-installid
db.sqlite
db.sqlite-shm
db.sqlite-wal
screenpipe_fts_migrate.sh
screenpipe_sync_updated.sh
U
screenpipe_sync.sh
M
screenpipe.db
Outline Section
OUTLINE
OUTLINE
Timeline Section
TIMELINE
TIMELINE
app_settings.json, Editor Group 1
screenpipe_sync.sh, Editor Group 1
screenpipe_fts_migrate.sh, Editor Group 1
screenpipe_sync_updated.sh, preview, Editor Group 1
pipe.md, Editor Group 1
.env, Editor Group 1
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
done
step "Reconciling NAS schema with source"
for tbl in "${ALL_SYNC_TABLES[@]}"; do
ensure_columns "$tbl"
done
run_sqlite_heredoc "creating indexes" "
ATTACH '$NAS_DB' AS nas;
-- vision
CREATE INDEX IF NOT EXISTS nas.idx_frames_timestamp ON frames(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_frames_app_name ON frames(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_window_name ON frames(window_name);
CREATE INDEX IF NOT EXISTS nas.idx_frames_video_chunk_id ON frames(video_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_frames_document_path ON frames(document_path) WHERE document_path IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_id ON elements(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_elements_frame_src_role ON elements(install_id, frame_id, source, role) WHERE text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_elements_onscreen_frame ON elements(install_id, frame_id) WHERE on_screen = 1 AND text IS NOT NULL;
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_timestamp ON ui_events(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_app_name ON ui_events(app_name);
CREATE INDEX IF NOT EXISTS nas.idx_ui_events_frame_id ON ui_events(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_ocr_text_frame_id ON ocr_text(install_id, frame_id);
CREATE INDEX IF NOT EXISTS nas.idx_meetings_start ON meetings(meeting_start);
CREATE INDEX IF NOT EXISTS nas.idx_video_chunks_device ON video_chunks(device_name);
-- audio
CREATE INDEX IF NOT EXISTS nas.idx_audio_chunks_timestamp ON audio_chunks(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_chunk_id ON audio_transcriptions(install_id, audio_chunk_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_timestamp ON audio_transcriptions(timestamp);
CREATE INDEX IF NOT EXISTS nas.idx_audio_trans_speaker ON audio_transcriptions(install_id, speaker_id, timestamp DESC);
CREATE INDEX IF NOT EXISTS nas.idx_speaker_emb_speaker_id ON speaker_embeddings(install_id, speaker_id);
CREATE INDEX IF NOT EXISTS nas.idx_audio_tags_chunk_id ON audio_tags(install_id, audio_chunk_id);
DETACH nas;
"
# ─── FTS TABLES (contentless, install-safe) ───────────────────────────────
run_sqlite_heredoc "creating FTS tables" "
ATTACH '$NAS_DB' AS nas;
CREATE VIRTUAL TABLE IF NOT EXISTS nas.frames_fts USING fts5(
full_text, app_name, window_name, browser_url,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.elements_fts USING fts5(
text, role,
install_id UNINDEXED, source_id UNINDEXED, frame_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.ui_events_fts USING fts5(
text_content, app_name, window_title, element_name,
install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
CREATE VIRTUAL TABLE IF NOT EXISTS nas.audio_transcriptions_fts USING fts5(
transcription, device,
speaker_id UNINDEXED, install_id UNINDEXED, source_id UNINDEXED,
tokenize='unicode61'
);
DETACH nas;
"
# ─── BUILD COLUMN LISTS ───────────────────────────────────────────────────
FRAMES_COLS=$(build_col_list frames)
ELEMENTS_COLS=$(build_col_list elements)
ELEMENTS_COLS_E=$(build_col_list elements e)
UI_EVENTS_COLS=$(build_col_list ui_events)
OCR_TEXT_COLS=$(build_col_list ocr_text)
OCR_TEXT_COLS_O=$(build_col_list ocr_text o)
VIDEO_CHUNKS_COLS=$(build_col_list video_chunks)
MEETINGS_COLS=$(build_col_list meetings)
ACHUNKS_COLS=$(build_col_list audio_chunks)
ATRANS_COLS=$(build_col_list audio_transcriptions)
ATRANS_COLS_T=$(build_col_list audio_transcriptions t)
SPEAKERS_COLS=$(build_col_list speakers)
SEMB_COLS=$(build_col_list speaker_embeddings)
ATAGS_COLS=$(build_col_list audio_tags)
ATAGS_COLS_AT=$(build_col_list audio_tags at)
TAGS_COLS=$(build_col_list tags)
VTAGS_COLS=$(build_col_list vision_tags)
VTAGS_COLS_VT=$(build_col_list vision_tags vt)
# ─── SYNC VISION DATA ─────────────────────────────────────────────────────
step "Syncing vision data for $TARGET_DATE"
run_sqlite_heredoc "video_chunks" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.video_chunks ($VIDEO_CHUNKS_COLS, install_id)
SELECT $VIDEO_CHUNKS_COLS, '$INSTALL_ID' FROM main.video_chunks
WHERE id IN (
SELECT DISTINCT video_chunk_id FROM main.frames
WHERE date(timestamp) = '$TARGET_DATE' AND video_chunk_id IS NOT NULL
);
DETACH nas;
"
run_sqlite_heredoc "frames ($SRC_FRAMES rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.frames ($FRAMES_COLS, install_id)
SELECT $FRAMES_COLS, '$INSTALL_ID' FROM main.frames WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ocr_text ($SRC_OCR rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ocr_text ($OCR_TEXT_COLS, install_id)
SELECT $OCR_TEXT_COLS_O, '$INSTALL_ID' FROM main.ocr_text o
JOIN main.frames f ON o.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "ui_events ($SRC_UI rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.ui_events ($UI_EVENTS_COLS, install_id)
SELECT $UI_EVENTS_COLS, '$INSTALL_ID' FROM main.ui_events WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "elements ($SRC_ELEMENTS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.elements ($ELEMENTS_COLS, install_id)
SELECT $ELEMENTS_COLS_E, '$INSTALL_ID' FROM main.elements e
JOIN main.frames f ON e.frame_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "meetings ($SRC_MEETINGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.meetings ($MEETINGS_COLS, install_id)
SELECT $MEETINGS_COLS, '$INSTALL_ID' FROM main.meetings WHERE date(meeting_start) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC AUDIO DATA ──────────────────────────────────────────────────────
step "Syncing audio data for $TARGET_DATE"
run_sqlite_heredoc "speakers ($SRC_SPEAKERS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speakers ($SPEAKERS_COLS, install_id)
SELECT $SPEAKERS_COLS, '$INSTALL_ID' FROM main.speakers;
DETACH nas;
"
run_sqlite_heredoc "speaker_embeddings ($SRC_SEMB rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.speaker_embeddings ($SEMB_COLS, install_id)
SELECT $SEMB_COLS, '$INSTALL_ID' FROM main.speaker_embeddings;
DETACH nas;
"
run_sqlite_heredoc "audio_chunks ($SRC_ACHUNKS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_chunks ($ACHUNKS_COLS, install_id)
SELECT $ACHUNKS_COLS, '$INSTALL_ID' FROM main.audio_chunks WHERE date(timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions ($SRC_ATRANS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_transcriptions ($ATRANS_COLS, install_id)
SELECT $ATRANS_COLS_T, '$INSTALL_ID' FROM main.audio_transcriptions t
JOIN main.audio_chunks c ON t.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
run_sqlite_heredoc "audio_tags ($SRC_ATAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.audio_tags ($ATAGS_COLS, install_id)
SELECT $ATAGS_COLS_AT, '$INSTALL_ID' FROM main.audio_tags at
JOIN main.audio_chunks c ON at.audio_chunk_id = c.id
WHERE date(c.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── SYNC SHARED ──────────────────────────────────────────────────────────
step "Syncing shared tables (tags, vision_tags)"
run_sqlite_heredoc "tags ($SRC_TAGS rows, all)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.tags ($TAGS_COLS, install_id)
SELECT $TAGS_COLS, '$INSTALL_ID' FROM main.tags;
DETACH nas;
"
run_sqlite_heredoc "vision_tags ($SRC_VTAGS rows)" "
ATTACH '$NAS_DB' AS nas;
INSERT OR IGNORE INTO nas.vision_tags ($VTAGS_COLS, install_id)
SELECT $VTAGS_COLS_VT, '$INSTALL_ID' FROM main.vision_tags vt
JOIN main.frames f ON vt.vision_id = f.id
WHERE date(f.timestamp) = '$TARGET_DATE';
DETACH nas;
"
# ─── FTS UPDATE (contentless, auto-rowid, no collisions) ──────────────────
# No `rowid` specified; SQLite assigns a fresh one. install_id + source_id
# are UNINDEXED columns so JOIN-back-to-base queries work.
step "Updating FTS indexes"
run_sqlite_heredoc "frames_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.frames_fts(full_text, app_name, window_name, browser_url, install_id, source_id)
SELECT full_text, app_name, window_name, browser_url, install_id, id
FROM nas.frames
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND full_text IS NOT NULL AND full_text != '';
DETACH nas;
"
run_sqlite_heredoc "elements_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.elements_fts(text, role, install_id, source_id, frame_id)
SELECT e.text, e.role, e.install_id, e.id, e.frame_id
FROM nas.elements e
JOIN nas.frames f ON e.frame_id = f.id AND e.install_id = f.install_id
WHERE date(f.timestamp) = '$TARGET_DATE'
AND e.install_id = '$INSTALL_ID'
AND e.text IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "ui_events_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.ui_events_fts(text_content, app_name, window_title, element_name, install_id, source_id)
SELECT text_content, app_name, window_title, element_name, install_id, id
FROM nas.ui_events
WHERE date(timestamp) = '$TARGET_DATE'
AND install_id = '$INSTALL_ID'
AND text_content IS NOT NULL;
DETACH nas;
"
run_sqlite_heredoc "audio_transcriptions_fts" "
ATTACH '$NAS_DB' AS nas;
INSERT INTO nas.audio_transcriptions_fts(transcription, device, speaker_id, install_id, source_id)
SELECT t.transcription, COALESCE(t.device,''), t.speaker_id, t.install_id, t.id
FROM nas.audio_transcriptions t
JOIN nas.audio_chunks c ON t.audio_chunk_id = c.id AND t.install_id = c.install_id
WHERE date(c.timestamp) = '$TARGET_DATE'
AND t.install_id = '$INSTALL_ID'
AND t.transcription IS NOT NULL AND t.transcription != '';
DETACH nas;
"
# ─── VERIFY ───────────────────────────────────────────────────────────────
step "Verifying DB"
V_FRAMES=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ELEMENTS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM elements WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_UI=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ui_events WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_OCR=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM ocr_text WHERE install_id='$INSTALL_ID' AND frame_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_MEETINGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM meetings WHERE date(meeting_start) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ACHUNKS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID';")
V_ATRANS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_transcriptions WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_ATAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM audio_tags WHERE install_id='$INSTALL_ID' AND audio_chunk_id IN (SELECT id FROM audio_chunks WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
V_VTAGS=$(sqlite3 "$NAS_DB" "SELECT COUNT(*) FROM vision_tags WHERE install_id='$INSTALL_ID' AND vision_id IN (SELECT id FROM frames WHERE date(timestamp) = '$TARGET_DATE' AND install_id='$INSTALL_ID');")
check "frames" "$V_FRAMES" "$SRC_FRAMES"
check "elements" "$V_ELEMENTS" "$SRC_ELEMENTS"
check "ui_events" "$V_UI" "$SRC_UI"
check "ocr_text" "$V_OCR" "$SRC_OCR"
check "meetings" "$V_MEETINGS" "$SRC_MEETINGS"
check "audio_chunks" "$V_ACHUNKS" "$SRC_ACHUNKS"
check "audio_transcriptions" "$V_ATRANS" "$SRC_ATRANS"
check "audio_tags" "$V_ATAGS" "$SRC_ATAGS"
check "vision_tags" "$V_VTAGS" "$SRC_VTAGS"
fi
# ─── COPY FRAME DATA FOLDER ──────────────────────────────────────────────────
step "Copying frame data folder for $TARGET_DATE"
if [ -d "$DATA_SRC" ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync frames → NAS"
rsync -a --ignore-existing "$DATA_SRC/" "$NAS_DATA/$TARGET_DATE/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_FILES=$(ls "$NAS_DATA/$TARGET_DATE" 2>/dev/null | grep -v '^audio$' | wc -l | tr -d ' ')
SRC_FILES=$(ls "$DATA_SRC" | wc -l | tr -d ' ')
COPIED_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE" | cut -f1)
if [ "$COPIED_FILES" -ge "$SRC_FILES" ]; then
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync frames → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_FILES" "$COPIED_SIZE" | tee -a "$LOG_FILE"
else
printf "\r %-40s ✗ %s / %s files\n" "rsync frames → NAS" "$COPIED_FILES" "$SRC_FILES" | tee -a "$LOG_FILE"
fi
else
printf " %-40s %s\n" "rsync frames → NAS" "skipped (no source dir)"
fi
# ─── COPY AUDIO FILES ────────────────────────────────────────────────────────
# Audio is flat in ~/.screenpipe/data/ with date in filename, e.g.
# System Audio (output)_2026-05-11_13-48-12.mp4
# soundcore AeroClip (input)_2026-05-10_11-10-32.mp4
# Mirror to $NAS_DATA/<date>/audio/ so each day's archive is self-contained.
step "Copying audio files for $TARGET_DATE"
shopt -s nullglob
AUDIO_FILES=( "$HOME/.screenpipe/data/"*_"${TARGET_DATE}"_*.mp4 )
shopt -u nullglob
if [ ${#AUDIO_FILES[@]} -gt 0 ]; then
mkdir -p "$NAS_DATA/$TARGET_DATE/audio"
RSYNC_START=$(date +%s)
printf " %-40s " "rsync audio → NAS"
rsync -a --ignore-existing "${AUDIO_FILES[@]}" "$NAS_DATA/$TARGET_DATE/audio/" 2>>"$LOG_FILE"
RSYNC_DUR=$(( $(date +%s) - RSYNC_START ))
COPIED_AUDIO=$(ls "$NAS_DATA/$TARGET_DATE/audio" | wc -l | tr -d ' ')
AUDIO_SIZE=$(du -sh "$NAS_DATA/$TARGET_DATE/audio" | cut -f1)
printf "\r %-40s ✓ %dm%02ds (%s files, %s)\n" \
"rsync audio → NAS" "$(( RSYNC_DUR / 60 ))" "$(( RSYNC_DUR % 60 ))" \
"$COPIED_AUDIO" "$AUDIO_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync audio → NAS" "skipped (no audio for date)"
fi
# ─── COPY LOGS ────────────────────────────────────────────────────────────────
step "Copying screenpipe logs for $TARGET_DATE"
NAS_LOGS="$NAS_MOUNT/logs"
mkdir -p "$NAS_LOGS"
shopt -s nullglob
LOG_FILES=( "$HOME/.screenpipe/screenpipe.$TARGET_DATE."*.log )
shopt -u nullglob
if [ ${#LOG_FILES[@]} -gt 0 ]; then
printf " %-40s " "rsync logs → NAS"
rsync -a "${LOG_FILES[@]}" "$NAS_LOGS/" 2>>"$LOG_FILE"
TOTAL_SIZE=$(du -ch "${LOG_FILES[@]}" | tail -1 | cut -f1)
printf "✓ %d file(s), %s\n" "${#LOG_FILES[@]}" "$TOTAL_SIZE" | tee -a "$LOG_FILE"
else
printf " %-40s %s\n" "rsync logs → NAS" "skipped (no matching logs)"
fi
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
TOTAL_ELAPSED=$(( $(date +%s) - SCRIPT_START ))
DB_SIZE=$(du -sh "$NAS_DB" | cut -f1)
echo ""
log "Archive DB size: $DB_SIZE"
log "Total time: $(( TOTAL_ELAPSED / 60 ))m$(( TOTAL_ELAPSED % 60 ))s"
log "Sync complete for $TARGET_DATE (install $INSTALL_ID)"
log "========================================"
rsync -a "$HOME/.screenpipe/sync.log" "$NAS_LOGS/sync.log" 2>/dev/null || true
Implement and run pipe l…, Editor Group 2
remote SSH: nas
SSH: nas
screenpipe (Git) - master*, Checkout Branch/Tag...
master*
screenpipe (Git) - Synchronize Changes
No Problems
0
0
Forwarded Ports: 8766
1
Notifications
Sign In
Sign In
Shell Script
Editor Language Status: Inline Suggestions, next: $(copilot) No inline suggestion available, Inline suggestions
LF
UTF-8
Spaces: 2
Ln 846, Col 59
Info: Downloading VS Code Server...
Implement and run pipe logic
Session history
New session
Message actions
main.py
main.py
lets implement logic with pipes. how can I run it?
Thinking
Thinking
Let me look at the current project structure to understand what's already in place.
Bash
List project files
IN
find /volume1/screenpipe -type f | head -50 && echo "---" && ls /volume1/screenpipe
Copy code to clipboard
OUT
/volume1/screenpipe/.DS_Store
/volume1/screenpipe/screenpipe.db
/volume1/screenpipe/screenpipe_sync.sh
/volume1/screenpipe/app_settings.json
/volume1/screenpipe/.gitignore
/volume1/screenpipe/archive.db
/volume1/screenpipe/db.sqlite
/volume1/screenpipe/db.sqlite-wal
/volume1/screenpipe/db.sqlite-shm
/volume1/screenpipe/#recycle/desktop.ini
/volume1/screenpipe/#recycle/db.sqlite
/volume1/screenpipe/#recycle/Copy #1 of db.sqlite
/volume1/screenpipe/#recycle/.DS_Store
/volume1/screenpipe/#recycle/Copy #2 of db.sqlite
/volume1/screenpipe/#recycle/archive.db
/volume1/screenpipe/#recycle/Copy #1 of archive.db
/volume1/screenpipe/#recycle/Copy #2 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of archive.db
/volume1/screenpipe/#recycle/Copy #4 of archive.db
/volume1/screenpipe/#recycle/Copy #5 of archive.db
/volume1/screenpipe/#recycle/Copy #3 of db.sqlite
/volume1/screenpipe/#recycle/Copy #4 of db.sqlite
/volume1/screenpipe/#recycle/Copy #6 of archive.db
/volume1/screenpipe/#recycle/test.txt
/volume1/screenpipe/#recycle/Copy #7 of archive.db
/volume1/screenpipe/#recycle/Copy #8 of archive.db
/volume1/screenpipe/#recycle/archive.db-journal
/volume1/screenpipe/#recycle/Copy #1 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #2 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #3 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #4 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #6 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #7 of archive.db-journal
/volume1/screenpipe/#recycle/Copy #5 of db.sqlite
/volume1/screenpipe/pipes/.DS_Store
/volume1/screenpipe/app/.env
/volume1/screenpipe/app/cli.py
/volume1/screenpipe/app/.DS_Store
/volume1/screenpipe/app/db.py
/volume1/screenpipe/app/docker-compose.yml
/volume1/screenpipe/app/main.py
/volume1/screenpipe/app/requirements.txt
/volume1/screenpipe/app/Dockerfile
/volume1/screenpipe/data/.DS_Store
/volume1/screenpipe/.git/description
/volume1/screenpipe/.git/HEAD
/volume1/screenpipe/.git/index
/volume1/screenpipe/.git/COMMIT_EDITMSG
/volume1/screenpipe/#recycle/data/.DS_Store
---
app
app_settings.json
archive.db
data
db.sqlite
db.sqlite-shm
db.sqlite-wal
pipes
#recycle
screenpipe.db
screenpipe_sync.sh
Read
main.py
main.py
Bash
Check pipes directory and docker-compose
IN
ls /volume1/screenpipe/pipes/ && ls /volume1/screenpipe/app/ && cat /volume1/screenpipe/app/docker-compose.yml
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
cli.py
consumers
db.py
docker-compose.yml
Dockerfile
main.py
__pycache__
requirements.txt
static
services:
screenpipe-app:
build: .
container_name: screenpipe-app
restart: unless-stopped
ports:
- "8766:8000"
volumes:
- /volume1/screenpipe:/data
env_file:
- .env
environment:
TZ: Europe/Sofia
DB_PATH: /data/db.sqlite
sqlite-web-archive:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-archive
restart: unless-stopped
ports:
- "8767:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/archive.db"]
sqlite-web-live:
image: ghcr.io/coleifer/sqlite-web:latest
container_name: screenpipe-sqlweb-live
restart: unless-stopped
ports:
- "8768:8080"
volumes:
- /volume1/screenpipe:/data
command: ["-H", "[IP_ADDRESS]", "-r", "/data/db.sqlite"]
Read
requirements.txt
requirements.txt
Bash
Inspect a pipe directory
IN
ls /volume1/screenpipe/pipes/day-recap/ && cat /volume1/screenpipe/pipes/day-recap/pipe.json 2>/dev/null || ls /volume1/screenpipe/pipes/day-recap/
Copy code to clipboard
OUT
pipe.md
pipe.md
Read
cli.py
cli.py
Bash
List all pipes and their contents
IN
ls /volume1/screenpipe/pipes/ && for d in /volume1/screenpipe/pipes/*/; do echo "=== $d ==="; ls "$d"; done
Copy code to clipboard
OUT
ai-habits
day-recap
meeting-summary
standup-update
time-breakdown
video-export
=== /volume1/screenpipe/pipes/ai-habits/ ===
pipe.md
=== /volume1/screenpipe/pipes/day-recap/ ===
pipe.md
=== /volume1/screenpipe/pipes/meeting-summary/ ===
pipe.md
=== /volume1/screenpipe/pipes/standup-update/ ===
pipe.md
=== /volume1/screenpipe/pipes/time-breakdown/ ===
pipe.md
=== /volume1/screenpipe/pipes/video-export/ ===
pipe.md
Bash
Read pipe markdown files
IN
cat /volume1/screenpipe/pipes/day-recap/pipe.md && echo "===" && cat /volume1/screenpipe/pipes/meeting-summary/pipe.md 2>/dev/null | head -50
Copy code to clipboard
OUT
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
Thinking
Thinking
Bash
Read summary consumer
IN
ls /volume1/screenpipe/app/consumers/ && cat /volume1/screenpipe/app/consumers/summary.py
Copy code to clipboard
OUT
activity.py
audio.py
elements.py
__init__.py
interactions.py
ocr.py
__pycache__
report.py
summary.py
"""AI summary generator using Claude."""
import os
from datetime import date
from typing import Any
from consumers.activity import app_time, summary_stats, browser_urls, ui_event_summary
from consumers.ocr import deduplicated_text
from consumers.audio import formatted_transcript
SUMMARY_TYPES = {
"day_recap": {
"title": "Day Recap",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a concise day recap using EXACTLY this format:
## Summary
One sentence: what I mainly worked on today.
## Accomplishments
- Top 3 things I finished, with approximate times
- Name specific apps, files, or projects
## Key Moments
- Important things seen or heard, with timestamps
## Unfinished Work
- What to continue tomorrow
## Patterns
- Apps used most, topics that came up repeatedly
Only report what you can verify from the data. End with:
**Next step:** [most important thing to continue]""",
},
"standup": {
"title": "Standup Update",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
## Audio/speech:
{audio}
Write a brief standup update:
**Yesterday:** What I worked on (2-3 bullets)
**Today:** What I plan to continue (1-2 bullets)
**Blockers:** Any issues observed (or "None")
Keep it under 150 words. Only report what's verifiable from the data.""",
},
"focus_time": {
"title": "Focus & Distraction Analysis",
"prompt": """\
You are analyzing a person's computer activity for the day.
## App usage (minutes per app):
{app_time}
## Browser URLs visited:
{browser_urls}
## UI activity per app (clicks / keystrokes / app-switches):
{ui_events}
## Screen content (sampled every 5 minutes):
{ocr_text}
Analyze focus vs distraction patterns:
## Deep Work Periods
- When and how long were sustained focus sessions?
- What was being worked on?
## Distractions
- Which apps/sites were used recreationally?
- How much time was lost to context switching?
## Recommendations
- 2-3 concrete suggestions to improve focus tomorrow
Be specific with times and app names.""",
},
}
def _build_context(for_date: date) -> dict[str, str]:
apps = app_time(for_date)
app_lines = "\n".join(f"- {a['app_name']}: {a['minutes']} min" for a in apps[:20])
urls = browser_urls(for_date, limit=20)
url_lines = "\n".join(
f"- {u['browser_url'][:100]} ({u['minutes']} min)" for u in urls
)
ui_rows = ui_event_summary(for_date)
ui_lines = "\n".join(
f"- {r['app_name']}: {r['clicks']} clicks, {r['keystrokes']} keys, {r['switches']} switches"
for r in ui_rows[:15]
)
ocr_rows = deduplicated_text(for_date, chunk_minutes=5)
ocr_lines = "\n".join(
f"[{r['bucket']}] {r['app_name']} / {r['window_name'] or ''}: {r['text'][:200]}"
for r in ocr_rows[:100]
)
audio = formatted_transcript(for_date)
return {
"app_time": app_lines or "(no app data)",
"browser_urls": url_lines or "(no browser data)",
"ui_events": ui_lines or "(no UI event data)",
"ocr_text": ocr_lines or "(no screen data)",
"audio": audio[:3000] if len(audio) > 3000 else audio,
}
def generate(
summary_type: str = "day_recap",
for_date: date | None = None,
api_key: str | None = None,
) -> dict[str, Any]:
"""Generate an AI summary. Returns dict with 'title', 'content', 'date'."""
import anthropic
d = for_date or date.today()
key = api_key or os.environ.get("ANTHROPIC_API_KEY", "")
if not key:
return {
"title": "Error",
"content": "ANTHROPIC_API_KEY not set. Add it to your .env file.",
"date": str(d),
}
spec = SUMMARY_TYPES.get(summary_type)
if not spec:
return {"title": "Error", "content": f"Unknown summary type: {summary_type}", "date": str(d)}
stats = summary_stats(d)
if stats["total_frames"] == 0:
return {
"title": spec["title"],
"content": f"No screen data found for {d}.",
"date": str(d),
}
ctx = _build_context(d)
prompt = spec["prompt"].format(**ctx)
client = anthropic.Anthropic(api_key=key)
message = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
)
return {
"title": spec["title"],
"content": message.content[0].text,
"date": str(d),
"stats": stats,
}
Thinking
Thinking
Bash
Read all pipe.md files
IN
for f in /volume1/screenpipe/pipes/*/pipe.md; do echo "=== $f ==="; cat "$f"; echo; done
Copy code to clipboard
OUT
=== /volume1/screenpipe/pipes/ai-habits/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: AI Habits
description: "How you use AI tools — patterns and insights"
icon: "🤖"
featured: true
---
Search my recordings from the last 24 hours for AI tool usage. Use app_name filter for each tool separately: ChatGPT, Claude, Copilot, Cursor, Gemini, Perplexity. Use limit=5 per search, max 6 searches total.
Read screenpipe skill first.
Use this exact format:
## AI Tools Used
- List each tool with approximate time spent (e.g. "Claude: ~45min")
## What I Used Them For
- For each tool: coding, writing, research, or brainstorming
## Usage Patterns
- Do I switch between tools? Use them in bursts or steadily?
## Effectiveness
- Which tool appeared alongside completed work vs. abandoned attempts
If no AI usage is found, say so clearly. End with: "**Tip:** [one suggestion to use AI tools more effectively]"
=== /volume1/screenpipe/pipes/day-recap/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Day Recap
description: "Today's accomplishments, key moments, and unfinished work"
icon: "📋"
featured: true
---
Analyze my screen and audio recordings from today (last 16 hours only).
Read screenpipe skill first.
Use this exact format:
## Summary
One sentence: what I mainly did today.
## Accomplishments
- Top 3 things I finished, with timestamps (e.g. "2:30 PM")
- Name specific apps, files, or projects
## Key Moments
- Important things I saw, said, or heard — with timestamps
## Unfinished Work
- What I should continue tomorrow — name the app/file/task
## Patterns
- Apps I used most, topics that came up repeatedly
Only report what you can verify from the data. End with: "**Next step:** [most important thing to continue]"
=== /volume1/screenpipe/pipes/meeting-summary/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Meeting Summary
description: "Summarize meeting transcript with key takeaways and action items"
icon: "🤝"
featured: false
---
Summarize the meeting transcript provided in the context. Include key takeaways and action items. If the meeting is marked as ongoing, note that and summarize what's available so far.
Read screenpipe skill first.
Use this exact format:
## Meeting Summary
One sentence: what this meeting was about.
## Key Takeaways
- Top 3-5 important points discussed
- Include who said what when relevant
## Action Items
- [ ] Task — assigned to whom, deadline if mentioned
- [ ] Task — assigned to whom
## Decisions Made
- List any decisions or agreements reached
## Open Questions
- Anything unresolved or needing follow-up
Keep it concise and actionable.
=== /volume1/screenpipe/pipes/standup-update/pipe.md ===
---
schedule: manual
enabled: true
template: true
title: Standup Update
de...
|
Code
|
screenpipe_sync.sh — screenpipe [SSH: nas] — Modif screenpipe_sync.sh — screenpipe [SSH: nas] — Modified...
|
NULL
|
26654
|