* feat(telegram): bot intake → inbox + daily VPS pull sync
- mnemazine-telegram-bot.mjs: zero-dep long-poll bot, writes text/photo/doc/voice/audio/video into staging inbox; chat_id allowlist; --selftest
- mnemazine-telegram-sync.sh: daily rsync pull VPS buffer → local inbox, then npm run run
- launchd plist template for daily 09:00 schedule
* feat(telegram): Mini App — status/send/run-now + reverse-channel poller
- webapp/index.html: Telegram Mini App (theme-aware, minimal); buffer status, send-to-inbox, run-now
- mnemazine-webapp-server.mjs: localhost API, initData HMAC verify + user allowlist, /api/{status,send,run}; --selftest
- run-now reverse channel: API touches .run-now; poll.sh consumes flag, Mac pulls+runs
- poll.sh: 5-min launchd tick — manual flag or daily 09:00 window; writes .last-run for app
- sync.sh: drop exec so markers persist; plist → StartInterval 300
* docs: Telegram intake architecture (bot + Mini App), EN+RU, no secrets
Generic scheme — host/secrets/domain abstracted. Linked from both READMEs.
* feat(setup): guided step-by-step installer for fresh devices
- setup.sh: staged wizard, numbered-menu questions, gates each stage
- checks prereqs and says exactly what to install before continuing
- missing capability → 'Друг, значит этого тебе не оставим' + continue
- asks inbox location (repo vs Desktop); optional Telegram bot incl. VPS deploy
- MNEMAZINE_SETUP_DRYRUN=1 walks stages without installing/deploying
- README EN+RU point to it
* fix(telegram): C1/C2 — secrets out of git, two-phase move (no data loss)
Phase 0+1.1 of audit fix plan:
- poll.sh/sync.sh: drop hardcoded VPS host/key → placeholders + gitignored .mnemazine/config.env (fail-fast on placeholder)
- sync.sh: two-phase move — pull to staging, promote, run protocol, delete on VPS ONLY after success (closes --remove-source-files data-loss window); deletes only files it took
- config.env.example template; .mnemazine/config.env gitignored
- selftest chat_id fixture 1 → 1 (was real personal id)
* fix(telegram): C3/C4 — kill stored-XSS + initData replay window
- webapp: render inbox file names via textContent/createElement (was innerHTML — file names come from untrusted Telegram uploads); add strict CSP meta
- webapp-server: verifyInitData now rejects stale auth_date (default 24h TTL, MNEMAZINE_INITDATA_TTL); closes forever-valid captured initData
- selftest: assert stale initData rejected (C7 — test from the threat, not current behavior)
* fix(telegram): C5 reliability — stop storm, TTY-guard, fail-closed, DoS caps
Phase 2:
- poll.sh: write daily marker BEFORE sync (no 5-min storm on failure); mkdir single-flight lock (macOS has no flock) with 60-min stale steal; re-queue manual run-now on failure. plist: RunAtLoad
- setup.sh: read EOF/TTY guard (no infinite loop under curl|bash/CI); gate install.sh exit code (stage actually gates)
- bot: advance/persist offset only AFTER successful handle (at-least-once, no dropped message); fail-closed allowlist (empty = reject + log id, not accept-all); cap download size 30MB; sanitize file extension (no traversal)
- webapp-server: cap request body 64KB (413); 500 returns generic error, detail to stderr only
* feat(telegram): C6 vault-patterns — run audit, config.env boundary, idempotent setup
Phase 3:
- /api/run: flag now carries {at, by} audit (kept as coalescing flag, not a full job queue — single user/button; YAGNI)
- 3.2 fenceUntrusted already covered: digest/synthesize fence note bodies at the LLM boundary (mnemazine-llm.mjs); inbox stays raw by design
- setup.sh: writes .mnemazine/config.env (chmod 600) from entered VPS details so poll/sync read the boundary; idempotent pm2 (start||restart) for rerun-safe deploy
* feat(telegram): Phase 4 polish — confirm run, auto-refresh, access log, throttle
- frontend: tg.showConfirm before run (no accidental token-spend); auto-refresh status every 15s while visible + on visibilitychange
- server: structured access log (stderr {ts,user,method,path}); light per-user 1/sec write throttle (429)
---------
Co-authored-by: Зарубин Филипп <289370046+zarubinphil@users.noreply.github.com>
52 lines
2.0 KiB
Bash
Executable File
52 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Daily: pull buffered Telegram messages from the VPS into the local inbox,
|
|
# then run the Mnemazine protocol. Mac initiates (VPS can't reach Mac behind NAT).
|
|
# ponytail: rsync --remove-source-files = move; local protocol archives originals,
|
|
# so the VPS stays a thin transit buffer, not a second store.
|
|
set -euo pipefail
|
|
|
|
REPO="${MNEMAZINE_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
|
# Live host/key/paths live in a gitignored config, never hardcoded here.
|
|
[ -f "$REPO/.mnemazine/config.env" ] && . "$REPO/.mnemazine/config.env"
|
|
VPS="${MNEMAZINE_VPS:-root@YOUR_VPS_HOST}"
|
|
KEY="${MNEMAZINE_VPS_KEY:-$HOME/.ssh/id_rsa}"
|
|
REMOTE_INBOX="${MNEMAZINE_REMOTE_INBOX:-/var/www/mnemazine-inbox/}"
|
|
LOCAL_INBOX="$REPO/inbox/"
|
|
STAGING="$REPO/inbox/.staging/"
|
|
|
|
if [ "$VPS" = "root@YOUR_VPS_HOST" ]; then
|
|
echo "Set MNEMAZINE_VPS (and MNEMAZINE_VPS_KEY) in $REPO/.mnemazine/config.env" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$LOCAL_INBOX" "$STAGING"
|
|
SSH_E="ssh -i $KEY -o StrictHostKeyChecking=no"
|
|
|
|
# Two-phase move (C2: never delete the only copy before processing succeeds).
|
|
# 1) pull into staging WITHOUT deleting on the VPS, resumable on partial transfer.
|
|
rsync -avz --partial --exclude '.*' -e "$SSH_E" "$VPS:$REMOTE_INBOX" "$STAGING"
|
|
|
|
# 2) promote staged files into the live inbox (atomic rename, same filesystem).
|
|
# Record exactly which files we took, so we delete only those on the VPS later
|
|
# (messages that arrive during the run stay buffered, not deleted).
|
|
pulled=()
|
|
shopt -s dotglob nullglob
|
|
for f in "$STAGING"*; do
|
|
base="$(basename "$f")"
|
|
case "$base" in .*) continue ;; esac # skip dotfiles defensively
|
|
mv -f "$f" "$LOCAL_INBOX$base"
|
|
pulled+=("$base")
|
|
done
|
|
shopt -u dotglob nullglob
|
|
|
|
# 3) run the protocol; only AFTER it succeeds delete the taken files on the VPS.
|
|
cd "$REPO"
|
|
if npm run run; then
|
|
if [ "${#pulled[@]}" -gt 0 ]; then
|
|
printf '%s\n' "${pulled[@]}" | $SSH_E "$VPS" "cd ${REMOTE_INBOX%/} && xargs -d '\n' -r rm -f --"
|
|
fi
|
|
else
|
|
echo "protocol run failed — files are in local inbox, VPS copies kept for safety" >&2
|
|
exit 1
|
|
fi
|