#!/bin/bash
# ===== poll-outbox.sh - Archive completed tasks =====
# Runs via crontab on VPS

INBOX="$HOME/hermes/kanban/inbox/pending"
DONE="$HOME/hermes/kanban/outbox/done"
FAIL="$HOME/hermes/kanban/outbox/failed"
ARCHIVE="$HOME/hermes/kanban/archive"

mkdir -p "$ARCHIVE"

# Archive done tasks
for f in "$DONE"/*.json; do
  [ -f "$f" ] || continue
  mv "$f" "$ARCHIVE/"
  echo "[$(date +%H:%M:%S)] archived done: $(basename $f)"
done

# Archive failed tasks
for f in "$FAIL"/*.json; do
  [ -f "$f" ] || continue
  mv "$f" "$ARCHIVE/"
  echo "[$(date +%H:%M:%S)] archived failed: $(basename $f)"
done