Finish live run readiness tooling
This commit is contained in:
@@ -32,6 +32,23 @@ if [ ! -f package-lock.json ]; then
|
||||
bad "package-lock.json missing; npm audit/ci are not reproducible"
|
||||
fi
|
||||
|
||||
if [ "${MNEMAZINE_PREFLIGHT_SKIP_LLM:-0}" != "1" ]; then
|
||||
provider_hint="${MNEMAZINE_LLM:-}"
|
||||
if provider="$(node --input-type=module - "$provider_hint" <<'NODE'
|
||||
import { activeProvider, llmAvailable } from './scripts/mnemazine-llm.mjs'
|
||||
const provider = process.argv[2] || activeProvider()
|
||||
if (!llmAvailable(provider)) process.exit(1)
|
||||
console.log(provider)
|
||||
NODE
|
||||
)"; then
|
||||
ok "llm provider available: $provider"
|
||||
else
|
||||
bad "llm provider unavailable; set MNEMAZINE_LLM=codex or install/configure Claude/Codex"
|
||||
fi
|
||||
else
|
||||
warn "llm provider check skipped"
|
||||
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
|
||||
|
||||
Executable
+170
@@ -0,0 +1,170 @@
|
||||
#!/usr/bin/env node
|
||||
import { promises as fs } from 'node:fs'
|
||||
import { existsSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const argv = process.argv.slice(2)
|
||||
|
||||
function arg(name, fallback = '') {
|
||||
const hit = argv.find(a => a === `--${name}` || a.startsWith(`--${name}=`))
|
||||
if (!hit) return fallback
|
||||
return hit.includes('=') ? hit.split('=').slice(1).join('=') : argv[argv.indexOf(hit) + 1] || fallback
|
||||
}
|
||||
|
||||
const JSON_OUT = argv.includes('--json')
|
||||
const REQUIRE_OK = argv.includes('--require-ok')
|
||||
const ROOT = path.resolve(arg('root', process.env.MNEMAZINE_ROOT || process.cwd()))
|
||||
|
||||
function expandHome(value) {
|
||||
const home = process.env.HOME || ''
|
||||
return String(value || '').replace(/^\$HOME(?=\/|$)/, home).replace(/^~(?=\/|$)/, home)
|
||||
}
|
||||
|
||||
function unquote(value) {
|
||||
const trimmed = String(value || '').trim()
|
||||
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
||||
return trimmed.slice(1, -1)
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
|
||||
async function localConfig() {
|
||||
const file = path.join(ROOT, '.mnemazine/config.local.sh')
|
||||
const body = await fs.readFile(file, 'utf8').catch(() => '')
|
||||
const out = {}
|
||||
for (const line of body.split('\n')) {
|
||||
const match = line.match(/^\s*(?:export\s+)?(MNEMAZINE_(?:INBOX|VAULT|REPORTS|STATE))=(.+?)\s*$/)
|
||||
if (match) out[match[1]] = expandHome(unquote(match[2]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
async function readJson(file, fallback = null) {
|
||||
try { return JSON.parse(await fs.readFile(file, 'utf8')) } catch { return fallback }
|
||||
}
|
||||
|
||||
async function activeCount(dir) {
|
||||
let count = 0
|
||||
for (const item of await fs.readdir(dir, { withFileTypes: true }).catch(() => [])) {
|
||||
if (item.isFile() && !item.name.startsWith('.')) count += 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
async function newestFile(dir, ext) {
|
||||
const files = []
|
||||
for (const item of await fs.readdir(dir, { withFileTypes: true }).catch(() => [])) {
|
||||
if (!item.isFile() || !item.name.endsWith(ext)) continue
|
||||
const file = path.join(dir, item.name)
|
||||
files.push({ file, mtimeMs: (await fs.stat(file)).mtimeMs })
|
||||
}
|
||||
return files.sort((a, b) => b.mtimeMs - a.mtimeMs)[0]?.file || ''
|
||||
}
|
||||
|
||||
function rel(file, root = ROOT) {
|
||||
return file ? path.relative(root, file) || '.' : null
|
||||
}
|
||||
|
||||
async function status(root = ROOT) {
|
||||
const cfg = root === ROOT ? await localConfig() : {}
|
||||
const stateDir = path.resolve(process.env.MNEMAZINE_STATE || cfg.MNEMAZINE_STATE || path.join(root, '.mnemazine/state'))
|
||||
const reportsDir = path.resolve(process.env.MNEMAZINE_REPORTS || cfg.MNEMAZINE_REPORTS || path.join(root, 'reports'))
|
||||
const inboxDir = path.resolve(process.env.MNEMAZINE_INBOX || cfg.MNEMAZINE_INBOX || path.join(root, 'inbox'))
|
||||
const nestedInbox = path.join(inboxDir, 'mnemazine-inbox')
|
||||
const lastRunFile = path.join(stateDir, 'last-run.json')
|
||||
const briefFile = path.join(stateDir, 'last-action-brief.md')
|
||||
const lastRun = await readJson(lastRunFile)
|
||||
const latestHtml = await newestFile(reportsDir, '.html')
|
||||
const latestMd = await newestFile(reportsDir, '.md')
|
||||
const inbox = await activeCount(inboxDir)
|
||||
const nested = existsSync(nestedInbox) ? await activeCount(nestedInbox) : 0
|
||||
const failures = []
|
||||
if (!lastRun) failures.push('last-run.json missing')
|
||||
if (lastRun && !lastRun.ok) failures.push(lastRun.failure || (lastRun.failures || []).join('; ') || 'last run failed')
|
||||
if (lastRun?.deep_required && !lastRun.deep) failures.push('strict run was not deep')
|
||||
if (lastRun?.deep_required && lastRun?.synthesize?.degraded) failures.push('deep synthesis degraded')
|
||||
if (lastRun?.deep_required && lastRun?.strict_archive_knowledge !== true) failures.push('strict archive gate missing')
|
||||
if (!existsSync(briefFile)) failures.push('last-action-brief.md missing')
|
||||
if (!latestHtml) failures.push('HTML report missing')
|
||||
return {
|
||||
ok: failures.length === 0,
|
||||
failures,
|
||||
inbox,
|
||||
nested_inbox: nested,
|
||||
last_run: lastRun ? {
|
||||
ok: Boolean(lastRun.ok),
|
||||
processed: Number(lastRun.processed || 0),
|
||||
cached_only: Number(lastRun.cached_only || 0),
|
||||
failed: Number(lastRun.failed || 0),
|
||||
archived: Number(lastRun.archived || 0),
|
||||
deep: Boolean(lastRun.deep),
|
||||
deep_required: Boolean(lastRun.deep_required),
|
||||
strict_archive_knowledge: Boolean(lastRun.strict_archive_knowledge),
|
||||
atomized: Number(lastRun.synthesize?.atomized || 0),
|
||||
enriched: Number(lastRun.synthesize?.enriched || 0),
|
||||
started_at: lastRun.started_at || null,
|
||||
finished_at: lastRun.finished_at || null
|
||||
} : null,
|
||||
paths: {
|
||||
inbox: inboxDir,
|
||||
state: rel(stateDir, root),
|
||||
last_run: rel(lastRunFile, root),
|
||||
brief: existsSync(briefFile) ? rel(briefFile, root) : null,
|
||||
latest_html: rel(latestHtml, root),
|
||||
latest_md: rel(latestMd, root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function selftest() {
|
||||
const temp = await fs.mkdtemp(path.join(process.env.TMPDIR || '/tmp', 'mnemazine-live-status-'))
|
||||
await fs.mkdir(path.join(temp, '.mnemazine/state'), { recursive: true })
|
||||
await fs.mkdir(path.join(temp, 'reports'), { recursive: true })
|
||||
await fs.mkdir(path.join(temp, 'inbox'), { recursive: true })
|
||||
await fs.writeFile(path.join(temp, '.mnemazine/state/last-action-brief.md'), '# Brief\n', 'utf8')
|
||||
await fs.writeFile(path.join(temp, 'reports/live.html'), '<!doctype html><html></html>', 'utf8')
|
||||
await fs.writeFile(path.join(temp, 'reports/live.md'), '# Report\n', 'utf8')
|
||||
await fs.writeFile(path.join(temp, '.mnemazine/state/last-run.json'), JSON.stringify({
|
||||
ok: true,
|
||||
processed: 2,
|
||||
cached_only: 1,
|
||||
failed: 0,
|
||||
archived: 3,
|
||||
deep: true,
|
||||
deep_required: true,
|
||||
strict_archive_knowledge: true,
|
||||
synthesize: { atomized: 2, enriched: 2 },
|
||||
started_at: '2099-01-01T00:00:00.000Z',
|
||||
finished_at: '2099-01-01T00:01:00.000Z'
|
||||
}, null, 2), 'utf8')
|
||||
const s = await status(temp)
|
||||
await fs.rm(temp, { recursive: true, force: true })
|
||||
if (!s.ok || s.last_run.processed !== 2 || s.last_run.archived !== 3) throw new Error('live status selftest failed')
|
||||
console.log('live-status selftest ok')
|
||||
}
|
||||
|
||||
function printText(s) {
|
||||
const run = s.last_run
|
||||
console.log(`Status: ${s.ok ? 'ok' : 'failed'}`)
|
||||
if (s.failures.length) console.log(`Failures: ${s.failures.join('; ')}`)
|
||||
console.log(`Inbox: ${s.inbox}${s.nested_inbox ? ` (+${s.nested_inbox} nested)` : ''}`)
|
||||
if (run) {
|
||||
console.log(`Run: processed=${run.processed} cached=${run.cached_only} failed=${run.failed} archived=${run.archived}`)
|
||||
console.log(`Deep: ${run.deep ? 'yes' : 'no'} required=${run.deep_required ? 'yes' : 'no'} strict_archive=${run.strict_archive_knowledge ? 'yes' : 'no'}`)
|
||||
console.log(`Atoms: atomized=${run.atomized} enriched=${run.enriched}`)
|
||||
if (run.finished_at) console.log(`Finished: ${run.finished_at}`)
|
||||
}
|
||||
if (s.paths.latest_html) console.log(`Report: ${s.paths.latest_html}`)
|
||||
if (s.paths.brief) console.log(`Brief: ${s.paths.brief}`)
|
||||
if (s.paths.last_run) console.log(`State: ${s.paths.last_run}`)
|
||||
}
|
||||
|
||||
if (argv.includes('--selftest')) {
|
||||
selftest().catch(error => { console.error(error.message || error); process.exit(1) })
|
||||
} else {
|
||||
status().then(s => {
|
||||
if (JSON_OUT) console.log(JSON.stringify(s, null, 2))
|
||||
else printText(s)
|
||||
if (REQUIRE_OK && !s.ok) process.exit(1)
|
||||
}).catch(error => { console.error(error.message || error); process.exit(1) })
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// Provider-abstracted LLM bridge for Mnemazine. Code-first engine is Claude
|
||||
// (headless `claude -p`); Codex is kept at parity (same llmJson contract) so
|
||||
// anything that works via Claude also works via Codex.
|
||||
// provider: MNEMAZINE_LLM = 'claude' (default) | 'codex'
|
||||
// provider: MNEMAZINE_LLM = 'claude' | 'codex' (unset = auto: Claude, else Codex)
|
||||
// Both run as schema-instructed, web-capable headless agents. Default pipeline
|
||||
// never calls either — only the opt-in --deep path does.
|
||||
import { spawnSync, spawn } from 'node:child_process'
|
||||
@@ -27,7 +27,7 @@ function runProc(bin, args, { input, timeoutMs, cwd } = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
const DEFAULT_PROVIDER = process.env.MNEMAZINE_LLM || 'claude'
|
||||
const CONFIG_PROVIDER = process.env.MNEMAZINE_LLM || ''
|
||||
const TIMEOUT_MS = Number(process.env.MNEMAZINE_LLM_TIMEOUT_MS || '420000')
|
||||
const CODEX_BIN = process.env.MNEMAZINE_CODEX_BIN || '/Applications/Codex.app/Contents/Resources/codex'
|
||||
|
||||
@@ -73,11 +73,18 @@ function binExists(bin) {
|
||||
return which.status === 0 && Boolean(which.stdout.trim())
|
||||
}
|
||||
|
||||
export function activeProvider(opts = {}) {
|
||||
return opts.provider || DEFAULT_PROVIDER
|
||||
export function defaultProvider() {
|
||||
if (CONFIG_PROVIDER) return CONFIG_PROVIDER
|
||||
if (binExists(resolveClaudeBin())) return 'claude'
|
||||
if (binExists(CODEX_BIN)) return 'codex'
|
||||
return 'claude'
|
||||
}
|
||||
|
||||
export function llmAvailable(provider = DEFAULT_PROVIDER) {
|
||||
export function activeProvider(opts = {}) {
|
||||
return opts.provider || defaultProvider()
|
||||
}
|
||||
|
||||
export function llmAvailable(provider = activeProvider()) {
|
||||
return provider === 'codex' ? binExists(CODEX_BIN) : binExists(resolveClaudeBin())
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ async function checkSyntax() {
|
||||
'scripts/mnemazine-digest.mjs',
|
||||
'scripts/mnemazine-report-quality-gate.mjs',
|
||||
'scripts/mnemazine-complete-check.mjs',
|
||||
'scripts/mnemazine-live-status.mjs',
|
||||
'scripts/mnemazine-release-check.mjs'
|
||||
]
|
||||
for (const script of scripts) {
|
||||
@@ -333,6 +334,7 @@ async function qualityAndPublicChecks() {
|
||||
await must('webapp selftest', process.execPath, ['scripts/mnemazine-webapp-server.mjs', '--selftest'])
|
||||
await must('telegram bot selftest', process.execPath, ['scripts/mnemazine-telegram-bot.mjs', '--selftest'])
|
||||
await must('weekly state selftest', process.execPath, ['scripts/mnemazine-weekly-state.mjs', '--selftest'])
|
||||
await must('live status selftest', process.execPath, ['scripts/mnemazine-live-status.mjs', '--selftest'])
|
||||
await must('demo vault quality', 'npm', ['run', 'quality', '--', '--vault', 'demo/vault'])
|
||||
await reportQualityGateSmoke()
|
||||
await completeGateSmoke()
|
||||
|
||||
@@ -7,14 +7,9 @@ cd "$ROOT"
|
||||
git pull --ff-only
|
||||
MNEMAZINE_FROM_SETUP=1 MNEMAZINE_SKIP_DEPS=1 bash install.sh
|
||||
|
||||
bash -n bin/mnemazine install.sh setup.sh scripts/mnemazine-desktop-protocol.sh scripts/mnemazine-telegram-sync.sh scripts/mnemazine-update.sh
|
||||
node --check scripts/mnemazine-run.mjs
|
||||
node --check scripts/mnemazine-complete-check.mjs
|
||||
node --check scripts/mnemazine-synthesize.mjs
|
||||
node --check scripts/mnemazine-verify.mjs
|
||||
npm run selftest:security
|
||||
npm run audit:security
|
||||
npm run audit:local
|
||||
|
||||
echo "Mnemazine updated."
|
||||
echo "Preflight before live run: npm run preflight:live"
|
||||
echo "Run from chat: Mnemazine"
|
||||
echo "Run from terminal: mnemazine"
|
||||
|
||||
Reference in New Issue
Block a user