diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index 22c9af1..0fe80a4 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -47,6 +47,8 @@ jobs: run: npm run audit:local - name: Run setup dry-run smoke run: printf '2\n2\n2\n' | MNEMAZINE_SETUP_DRYRUN=1 bash setup.sh + - name: Run live preflight smoke + run: MNEMAZINE_PREFLIGHT_ALLOW_EMPTY=1 MNEMAZINE_PREFLIGHT_SKIP_REMOTE=1 npm run preflight:live - name: Run release test suite run: npm test - name: Run release gate directly diff --git a/README.md b/README.md index aaeeafc..3facb9e 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,29 @@ To test the Desktop path without touching the live inbox or vault: npm run protocol:desktop:dry-run ``` +Before a real live run, run the preflight: + +```bash +npm run preflight:live +``` + +It checks that tracked code is clean, `HEAD` matches `origin/main`, local +security gates pass, the Desktop dry-run passes, and the inbox has active +files. If preflight fails, do not run `npm start`; fix the cause first. + +After a live run, inspect the result: + +```bash +cat .mnemazine/state/last-run.json +cat .mnemazine/state/last-action-brief.md +ls -t reports/* | head +npm run complete -- --require-deep +``` + +If a strict run fails before archive, that is safe: source files stay in the +inbox. Do not move or delete them by hand. Read +`.mnemazine/state/last-run.json`, fix the cause, and run again. + ## Website Ingestion Mnemazine can ingest a website and convert its useful pages into structured notes: diff --git a/README.ru.md b/README.ru.md index b880f9a..a121002 100644 --- a/README.ru.md +++ b/README.ru.md @@ -169,6 +169,29 @@ mnemazine npm run protocol:desktop:dry-run ``` +Перед настоящим live-прогоном запусти preflight: + +```bash +npm run preflight:live +``` + +Он проверяет, что код чистый, `HEAD` совпадает с `origin/main`, локальные +security gates зелёные, Desktop dry-run проходит, а в inbox есть активные +файлы. Если preflight упал — `npm start` не запускай, сначала исправь причину. + +После live-прогона проверь итог: + +```bash +cat .mnemazine/state/last-run.json +cat .mnemazine/state/last-action-brief.md +ls -t reports/* | head +npm run complete -- --require-deep +``` + +Если строгий прогон падает до архива — это нормально и безопасно: исходники +остаются в inbox. Не переносите и не удаляйте их руками. Читай +`.mnemazine/state/last-run.json`, исправляй причину и запускай снова. + ## Парсинг сайтов Mnemazine умеет забирать сайт и превращать его полезные страницы в структурированные заметки: diff --git a/docs/installation.md b/docs/installation.md index 82b7efa..4b6404d 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -69,6 +69,21 @@ npm run protocol:desktop:dry-run This runs the Desktop protocol against temporary inbox/vault/cache/archive paths. It never archives, deletes, or rewrites the live Desktop inbox. +## Live Preflight + +```bash +npm run preflight:live +``` + +Before a real `npm start`, this checks that tracked code is clean, `HEAD` +matches `origin/main`, the local security audit passes, the Desktop dry-run +passes, and the inbox has active files. Empty inbox or dirty code is a failure. +To test the command itself without files, temporarily set +`MNEMAZINE_PREFLIGHT_ALLOW_EMPTY=1`. + +After a live run, inspect `.mnemazine/state/last-run.json`, +`.mnemazine/state/last-action-brief.md`, and the newest files in `reports/`. + ## Agent Skills If Codex or Claude skill folders exist, the installer copies portable skills there. If they do not exist, nothing breaks. diff --git a/docs/installation.ru.md b/docs/installation.ru.md index 073384c..1d0310e 100644 --- a/docs/installation.ru.md +++ b/docs/installation.ru.md @@ -69,6 +69,20 @@ npm run protocol:desktop:dry-run Команда гоняет Desktop-протокол на временных inbox/vault/cache/archive. Live Desktop inbox не архивируется, не удаляется и не переписывается. +## Live preflight + +```bash +npm run preflight:live +``` + +Перед настоящим `npm start` команда проверяет чистоту tracked-кода, совпадение +с `origin/main`, локальный security audit, Desktop dry-run и наличие файлов в +inbox. Пустой inbox или грязный код — fail. Для проверки самой команды без +файлов можно временно поставить `MNEMAZINE_PREFLIGHT_ALLOW_EMPTY=1`. + +После live-прогона смотри `.mnemazine/state/last-run.json`, +`.mnemazine/state/last-action-brief.md` и свежие файлы в `reports/`. + ## Agent Skills Если есть папки skills для Codex или Claude — установщик копирует туда переносимые skills. Если их нет, ничего не ломается. diff --git a/package.json b/package.json index 707cd22..25f1603 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "test": "npm run release-check", "audit:security": "npm audit --audit-level=moderate", "audit:local": "bash scripts/mnemazine-audit-local.sh", + "preflight:live": "bash scripts/mnemazine-live-preflight.sh", "selftest:security": "node scripts/mnemazine-verify.mjs --selftest && node scripts/mnemazine-webapp-server.mjs --selftest && node scripts/mnemazine-telegram-bot.mjs --selftest && node scripts/mnemazine-weekly-state.mjs --selftest", "run": "node scripts/mnemazine-run.mjs", "protocol:desktop": "bash scripts/mnemazine-desktop-protocol.sh", diff --git a/scripts/mnemazine-live-preflight.sh b/scripts/mnemazine-live-preflight.sh new file mode 100755 index 0000000..6c3b2ef --- /dev/null +++ b/scripts/mnemazine-live-preflight.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="${MNEMAZINE_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" +cd "$ROOT" + +fail=0 + +ok() { printf 'ok %s\n' "$*"; } +warn() { printf 'warn %s\n' "$*" >&2; } +bad() { printf 'fail %s\n' "$*" >&2; fail=1; } + +need_cmd() { + if command -v "$1" >/dev/null 2>&1; then ok "$1 found"; else bad "$1 missing"; fi +} + +active_count() { + local dir="$1" + find "$dir" -maxdepth 1 -type f ! -name '.*' 2>/dev/null | wc -l | tr -d ' ' +} + +need_cmd git +need_cmd node +need_cmd npm + +if command -v node >/dev/null 2>&1; then + node_major="$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)" + if [ "$node_major" -ge 20 ]; then ok "node >=20"; else bad "node >=20 required"; fi +fi + +if [ ! -f package-lock.json ]; then + bad "package-lock.json missing; npm audit/ci are not reproducible" +fi + +if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + dirty="$(git status --porcelain --untracked-files=no)" + if [ -n "$dirty" ]; then + if [ "${MNEMAZINE_PREFLIGHT_ALLOW_DIRTY:-0}" = "1" ]; then + warn "tracked git changes present, allowed by MNEMAZINE_PREFLIGHT_ALLOW_DIRTY=1" + else + bad "tracked git changes present; commit or stash before live run" + printf '%s\n' "$dirty" >&2 + fi + else + ok "tracked git tree clean" + fi + + if [ "${MNEMAZINE_PREFLIGHT_SKIP_REMOTE:-0}" != "1" ] && git remote get-url origin >/dev/null 2>&1; then + if git fetch origin main >/dev/null 2>&1; then + head="$(git rev-parse HEAD)" + remote="$(git rev-parse origin/main)" + if [ "$head" = "$remote" ]; then ok "HEAD matches origin/main"; else bad "HEAD differs from origin/main"; fi + else + bad "could not fetch origin/main" + fi + fi +fi + +npm run audit:local +npm run protocol:desktop:dry-run + +env_inbox="${MNEMAZINE_INBOX:-}" +[ -f "$ROOT/.mnemazine/config.local.sh" ] && . "$ROOT/.mnemazine/config.local.sh" +base_inbox="${env_inbox:-${MNEMAZINE_INBOX:-$HOME/Desktop/Mnemazine Inbox}}" +nested_inbox="$base_inbox/mnemazine-inbox" +base_count="$(active_count "$base_inbox")" +nested_count=0 +[ -d "$nested_inbox" ] && nested_count="$(active_count "$nested_inbox")" +total_count=$((base_count + nested_count)) + +printf 'live inbox: %s (%s files)\n' "$base_inbox" "$base_count" +[ "$nested_count" -gt 0 ] && printf 'nested legacy inbox: %s (%s files)\n' "$nested_inbox" "$nested_count" + +if [ "$total_count" -eq 0 ] && [ "${MNEMAZINE_PREFLIGHT_ALLOW_EMPTY:-0}" != "1" ]; then + bad "no active inbox files; add files before live run" +fi + +if [ "$fail" -ne 0 ]; then + echo "live preflight failed" >&2 + exit 1 +fi + +echo "live preflight passed" +echo "next: npm start"