From 4ed7a715186c4da30283f574fe1b364cfb10ae68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=80=D1=83=D0=B1=D0=B8=D0=BD=20=D0=A4=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BF=D0=BF?= <289370046+zarubinphil@users.noreply.github.com> Date: Wed, 17 Jun 2026 22:32:54 +0300 Subject: [PATCH] Enforce Mnemazine vault protocol --- .gitignore | 1 + scripts/check-public-release.sh | 4 ++- scripts/mnemazine-release-check.mjs | 11 ++++-- scripts/mnemazine-run.mjs | 43 +++++++++++++++++++++--- scripts/mnemazine-vault-quality-gate.mjs | 6 ++++ 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 609f7fc..27b5ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ .mnemazine/bin/ .mnemazine/archive/ .mnemazine/state/ +.mnemazine/quarantine/ .mnemazine/reprocess-video-inbox/ inbox/* !inbox/.gitkeep diff --git a/scripts/check-public-release.sh b/scripts/check-public-release.sh index bdfb7e4..683d37b 100755 --- a/scripts/check-public-release.sh +++ b/scripts/check-public-release.sh @@ -6,7 +6,9 @@ ROOT="${1:-$(cd "$(dirname "$0")/.." && pwd)}" # Private markers (machine paths, IPs, personal/project names) that must never ship publicly. PRIVATE_MARKERS='/Users/fil|72\.56|root@|Полезные знания|_ВХОДЯЩИЕ|TODOCUPS|ПКК|legal-practice|Adventure Book|AthenaOS|Филипп' # Token-like values (GitHub OAuth, OpenAI/Anthropic-style sk-, Slack xox*). -TOKEN_MARKERS='gho_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]+|xox[baprs]-[A-Za-z0-9-]+' +# Require realistic lengths and a non-word boundary before `sk-` to avoid +# false positives such as `risk-or-verification`. +TOKEN_MARKERS='gho_[A-Za-z0-9_]{20,}|(^|[^A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{20,}' # Pick a scanner. Prefer ripgrep; fall back to POSIX grep so the gate still runs # on machines without rg. A missing scanner must HARD-FAIL, never silently pass. diff --git a/scripts/mnemazine-release-check.mjs b/scripts/mnemazine-release-check.mjs index 418b625..a78ed37 100644 --- a/scripts/mnemazine-release-check.mjs +++ b/scripts/mnemazine-release-check.mjs @@ -69,6 +69,7 @@ async function demoSmoke() { await fs.mkdir(vault, { recursive: true }) await fs.mkdir(scripts, { recursive: true }) await fs.copyFile(path.join(ROOT, 'demo/inbox/example-guide.md'), path.join(inbox, 'example-guide.md')) + await fs.writeFile(path.join(inbox, 'empty-source.bin'), '') await fs.copyFile(path.join(ROOT, 'scripts/mnemazine-vault-quality-gate.mjs'), path.join(scripts, 'mnemazine-vault-quality-gate.mjs')) await must('demo intake smoke', process.execPath, ['scripts/mnemazine-run.mjs'], { @@ -93,8 +94,14 @@ async function demoSmoke() { if (!/type:\s*"knowledge-note"/.test(note)) throw new Error('demo smoke failed: note is not knowledge-note') if (!/source_hash:/.test(note) || !/local-media:/.test(note)) throw new Error('demo smoke failed: provenance missing') - const archived = (await listFiles(path.join(temp, '.mnemazine/archive'))).filter(file => file.endsWith('.md')) - if (archived.length !== 1) throw new Error(`demo smoke failed: expected 1 archived source, got ${archived.length}`) + const archived = await listFiles(path.join(temp, '.mnemazine/archive')) + if (archived.length !== 2) throw new Error(`demo smoke failed: expected 2 archived sources, got ${archived.length}`) + + const extractRecords = (await listFiles(path.join(temp, '.mnemazine/cache/extracted'))).filter(file => file.endsWith('.json')) + if (extractRecords.length !== 2) throw new Error(`demo smoke failed: expected 2 extract records, got ${extractRecords.length}`) + const cache = await readJson(path.join(temp, '.mnemazine/cache/processed-hashes.json')) + const cacheOnly = Object.values(cache).filter(value => value && typeof value === 'object' && value.status === 'needs_manual_context') + if (cacheOnly.length !== 1) throw new Error(`demo smoke failed: expected 1 cache-only source, got ${cacheOnly.length}`) } async function qualityAndPublicChecks() { diff --git a/scripts/mnemazine-run.mjs b/scripts/mnemazine-run.mjs index 14a9b7e..eabb637 100755 --- a/scripts/mnemazine-run.mjs +++ b/scripts/mnemazine-run.mjs @@ -15,6 +15,7 @@ const TRANSCRIPTS = path.join(ROOT, '.mnemazine/cache/video-transcripts') const VIDEO_AUDIO = path.join(ROOT, '.mnemazine/cache/video-audio') const VIDEO_FRAMES = path.join(ROOT, '.mnemazine/cache/video-frames') const VIDEO_QUEUE = path.join(ROOT, '.mnemazine/cache/video-queue.jsonl') +const EXTRACTS = path.join(ROOT, '.mnemazine/cache/extracted') const WHISPER_MODEL = process.env.MNEMAZINE_WHISPER_MODEL || '' const WHISPER_LANGUAGE = process.env.MNEMAZINE_WHISPER_LANGUAGE || 'ru' const VIDEO_FRAME_LIMIT = Number(process.env.MNEMAZINE_VIDEO_FRAME_LIMIT || '8') @@ -81,6 +82,14 @@ function bullets(text, max = 7) { return out } +function hasUsableExtraction(text) { + const clean = compact(text, 2000) + if (clean.length < 80) return false + if (/^(Video queued for local Whisper transcription|No extractable text)/i.test(clean)) return false + const alpha = (clean.match(/[A-Za-zА-Яа-яЁё]/g) || []).length + return alpha >= 50 +} + function isVideo(file) { return ['.mp4', '.mov', '.m4v', '.webm', '.mkv'].includes(path.extname(file).toLowerCase()) } @@ -228,8 +237,8 @@ type: "knowledge-note" source_type: "${ext}" source_ref: "${ref}" source_hash: "${hash}" -verified: "local extraction only" -status: "final-local" +verified: "extraction reviewed; external verification required" +status: "candidate" --- # ${title} @@ -258,7 +267,7 @@ ${facts.length ? facts.map(item => `- ${item}`).join('\n') : '- Local extraction ## Verification -- Status: local extraction only. +- Status: extraction reviewed; external verification required. - Evidence: SHA-256 source hash. - Limitation: external facts, dates, prices, stars, and security claims are not confirmed by this run. @@ -274,6 +283,23 @@ ${facts.length ? facts.map(item => `- ${item}`).join('\n') : '- Local extraction ` } +async function writeExtractCache(source, hash, text, status) { + await ensureDir(EXTRACTS) + const ext = path.extname(source).toLowerCase().replace('.', '') || 'file' + const ref = sourceRef(hash) + const record = { + source_ref: ref, + source_hash: hash, + source_type: ext, + status, + extracted_at: new Date().toISOString(), + text_path: compact(text, 80) ? `${hash}.txt` : null + } + if (record.text_path) await fs.writeFile(path.join(EXTRACTS, record.text_path), text, 'utf8') + await fs.writeFile(path.join(EXTRACTS, `${hash}.json`), JSON.stringify(record, null, 2), 'utf8') + return record +} + async function archiveFile(file, hash) { const month = new Date().toISOString().slice(0, 7) const dir = path.join(ARCHIVE, month) @@ -294,12 +320,21 @@ async function main() { const entries = (await fs.readdir(INBOX, { withFileTypes: true })) .filter(d => d.isFile() && !d.name.startsWith('.')) let processed = 0 + let cachedOnly = 0 const toArchive = [] for (const entry of entries) { const file = path.join(INBOX, entry.name) const hash = await sha256(file) if (cache[hash]) continue const text = await extract(file) + if (!hasUsableExtraction(text)) { + const record = await writeExtractCache(file, hash, text, 'needs_manual_context') + cache[hash] = { status: record.status, source_ref: record.source_ref, cache: path.relative(ROOT, path.join(EXTRACTS, `${hash}.json`)) } + toArchive.push({ file, hash }) + cachedOnly += 1 + continue + } + await writeExtractCache(file, hash, text, 'extracted_for_note') const title = inferTitle(text, 'Unextractable local source') const noteName = `${new Date().toISOString().slice(0, 10)}-${slugify(title)}-${hash.slice(0, 12)}.md` const notePath = path.join(VAULT, '01 Concepts', noteName) @@ -317,7 +352,7 @@ async function main() { if (spawnSync('graphify', ['--version'], { encoding: 'utf8' }).status === 0) { spawnSync('graphify', ['update', VAULT], { stdio: 'inherit' }) } - console.log(JSON.stringify({ inbox: entries.length, processed, archived: archived.length, vault: VAULT }, null, 2)) + console.log(JSON.stringify({ inbox: entries.length, processed, cached_only: cachedOnly, archived: archived.length, vault: VAULT }, null, 2)) } main().catch(err => { diff --git a/scripts/mnemazine-vault-quality-gate.mjs b/scripts/mnemazine-vault-quality-gate.mjs index 79619d4..185f5d5 100755 --- a/scripts/mnemazine-vault-quality-gate.mjs +++ b/scripts/mnemazine-vault-quality-gate.mjs @@ -17,10 +17,16 @@ const VAULT = path.resolve(arg('vault', process.env.MNEMAZINE_VAULT || path.join const badMarkers = [ /raw\s+ocr/i, /сырой\s+ocr(?!\s+исключ[её]н)/i, + /No extractable text/i, + /Unextractable local source/i, + /needs_manual_context/i, /распознанный\s+текст\s+без\s+обработки/i, + /Video keyframe OCR/i, + /Video transcript from local Whisper/i, /intake-draft/i, /draft-local/i, /локальное\s+извлечение/i, + /local extraction only/i, /\btemp_image[_-]/i, /\bIMG_\d+/, /\.(WEBP|PNG|JPE?G|HEIC|TIFF)\b/,