release: Mnemazine
Local-first memory system: raw material in, finished notes out. Synthesis on write. This release brings a guided install that explains itself and ends with a live demo pass, eleven fixes to the knowledge pipeline found by running it against a real archive of 216 sources, and a documentation pass in the project's own voice.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
import { promises as fs } from 'node:fs'
|
||||
import { existsSync } from 'node:fs'
|
||||
import { spawn } from 'node:child_process'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
@@ -35,7 +36,7 @@ async function countVaultFiles(vault) {
|
||||
|
||||
function runWorker(job) {
|
||||
return new Promise(resolve => {
|
||||
const child = spawn(process.execPath, [
|
||||
const args = [
|
||||
'scripts/mnemazine-semantic-batches.mjs',
|
||||
'--vault', job.vault,
|
||||
'--graph', job.graph,
|
||||
@@ -45,7 +46,12 @@ function runWorker(job) {
|
||||
'--start', String(job.start),
|
||||
'--limit', String(job.limit),
|
||||
'--no-cluster'
|
||||
], { cwd: ROOT, env: process.env, stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
]
|
||||
if (job.backend) args.push('--backend', job.backend)
|
||||
if (job.model) args.push('--model', job.model)
|
||||
if (job.cacheDir) args.push('--cache-dir', job.cacheDir)
|
||||
if (!job.cache) args.push('--no-cache')
|
||||
const child = spawn(process.execPath, args, { cwd: ROOT, env: process.env, stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
const chunks = []
|
||||
const errors = []
|
||||
child.stdout.on('data', chunk => chunks.push(chunk))
|
||||
@@ -69,9 +75,12 @@ function runWorker(job) {
|
||||
async function main() {
|
||||
const vault = resolveVault({ cli: arg('vault') })
|
||||
const graph = path.resolve(arg('graph', path.join(vault, 'graphify-out/graph.json')))
|
||||
const shardsDir = path.resolve(arg('shards-dir', path.join(vault, `.mnemazine/semantic-shards/${RUN_ID}`)))
|
||||
const shardsDir = path.resolve(arg('shards-dir', process.env.MNEMAZINE_SEMANTIC_SHARDS_DIR ? path.join(process.env.MNEMAZINE_SEMANTIC_SHARDS_DIR, RUN_ID) : path.join(vault, `.mnemazine/semantic-shards/${RUN_ID}`)))
|
||||
const logsDir = path.resolve(arg('logs-dir', path.join(shardsDir, 'logs')))
|
||||
const cacheDir = path.resolve(arg('cache-dir', process.env.MNEMAZINE_SEMANTIC_CACHE_DIR || path.join(vault, '.mnemazine/semantic-cache')))
|
||||
const manifestPath = path.join(shardsDir, 'manifest.json')
|
||||
const progressPath = path.join(shardsDir, 'progress.json')
|
||||
const startedAt = new Date().toISOString()
|
||||
const total = await countVaultFiles(vault)
|
||||
const start = Math.max(0, Number(arg('start', '0')))
|
||||
const limit = Number(arg('limit', String(Math.max(0, total - start))))
|
||||
@@ -79,12 +88,18 @@ async function main() {
|
||||
const batchSize = Math.max(1, Number(arg('batch-size', '1')))
|
||||
const excerptChars = Math.max(300, Number(arg('excerpt-chars', '600')))
|
||||
const maxTokens = Math.max(120, Number(arg('max-tokens', '360')))
|
||||
const backend = arg('backend', process.env.MNEMAZINE_GRAPHIFY_BACKEND || '')
|
||||
const model = arg('model', process.env.MNEMAZINE_GRAPHIFY_MODEL || '')
|
||||
const concurrency = Math.max(1, Number(arg('concurrency', String(Math.min(8, Math.max(1, os.cpus().length - 2))))))
|
||||
const dryRun = flag('dry-run')
|
||||
const resume = !flag('no-resume')
|
||||
const cache = !flag('no-cache')
|
||||
await fs.mkdir(shardsDir, { recursive: true })
|
||||
await fs.mkdir(logsDir, { recursive: true })
|
||||
|
||||
const end = Math.min(total, start + limit)
|
||||
const selected = Math.max(0, end - start)
|
||||
const hadManifest = existsSync(manifestPath)
|
||||
const jobs = []
|
||||
for (let i = start; i < end; i += chunkSize) {
|
||||
const size = Math.min(chunkSize, end - i)
|
||||
@@ -95,16 +110,22 @@ async function main() {
|
||||
graph,
|
||||
shardGraph: path.join(shardsDir, `${name}.json`),
|
||||
log: path.join(logsDir, `${name}.log`),
|
||||
done: path.join(shardsDir, `${name}.done.json`),
|
||||
start: i,
|
||||
limit: size,
|
||||
batchSize,
|
||||
excerptChars,
|
||||
maxTokens
|
||||
maxTokens,
|
||||
backend,
|
||||
model,
|
||||
cacheDir,
|
||||
cache,
|
||||
signature: JSON.stringify({ start: i, limit: size, batchSize, excerptChars, maxTokens, backend, model, cache })
|
||||
})
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
console.log(JSON.stringify({ ok: true, dry_run: true, vault, graph, shards_dir: shardsDir, manifest: manifestPath, total, selected: limit, start, chunk_size: chunkSize, batch_size: batchSize, excerpt_chars: excerptChars, max_tokens: maxTokens, concurrency, jobs: jobs.map(j => ({ name: j.name, start: j.start, limit: j.limit, graph: j.shardGraph })) }, null, 2))
|
||||
console.log(JSON.stringify({ ok: true, dry_run: true, vault, graph, shards_dir: shardsDir, manifest: manifestPath, progress: progressPath, cache_dir: cacheDir, cache, resume, total, selected, start, chunk_size: chunkSize, batch_size: batchSize, excerpt_chars: excerptChars, max_tokens: maxTokens, backend: backend || null, model: model || null, concurrency, jobs: jobs.map(j => ({ name: j.name, start: j.start, limit: j.limit, graph: j.shardGraph, done: j.done })) }, null, 2))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,26 +134,95 @@ async function main() {
|
||||
graph,
|
||||
shards_dir: shardsDir,
|
||||
total,
|
||||
selected: limit,
|
||||
selected,
|
||||
start,
|
||||
chunk_size: chunkSize,
|
||||
batch_size: batchSize,
|
||||
excerpt_chars: excerptChars,
|
||||
max_tokens: maxTokens,
|
||||
backend: backend || null,
|
||||
model: model || null,
|
||||
cache_dir: cacheDir,
|
||||
cache,
|
||||
resume,
|
||||
resumed: resume && hadManifest,
|
||||
concurrency,
|
||||
jobs: jobs.map(job => ({ name: job.name, start: job.start, limit: job.limit, graph: job.shardGraph, log: job.log }))
|
||||
progress: progressPath,
|
||||
jobs: jobs.map(job => ({ name: job.name, start: job.start, limit: job.limit, graph: job.shardGraph, log: job.log, done: job.done, signature: job.signature }))
|
||||
}, null, 2)}\n`, 'utf8')
|
||||
|
||||
let next = 0
|
||||
const done = []
|
||||
const skipped = []
|
||||
const active = new Map()
|
||||
async function completedJob(job) {
|
||||
if (!resume || !await fs.access(job.done).then(() => true).catch(() => false)) return false
|
||||
try {
|
||||
const marker = JSON.parse(await fs.readFile(job.done, 'utf8'))
|
||||
return marker.signature === job.signature && await fs.access(job.shardGraph).then(() => true).catch(() => false)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
async function writeProgress(phase = 'running') {
|
||||
const completed = done.length
|
||||
const failed = done.filter(j => j.code !== 0)
|
||||
const remaining = Math.max(0, jobs.length - completed)
|
||||
const elapsed = Math.max(0, Math.round((Date.now() - Date.parse(startedAt)) / 1000))
|
||||
const eta = completed > 0 && completed < jobs.length
|
||||
? Math.round((elapsed / completed) * (jobs.length - completed))
|
||||
: null
|
||||
await fs.writeFile(progressPath, `${JSON.stringify({
|
||||
ok: failed.length === 0,
|
||||
phase,
|
||||
vault,
|
||||
graph,
|
||||
shards_dir: shardsDir,
|
||||
manifest: manifestPath,
|
||||
started_at: startedAt,
|
||||
updated_at: new Date().toISOString(),
|
||||
elapsed_seconds: elapsed,
|
||||
eta_seconds: eta,
|
||||
total_jobs: jobs.length,
|
||||
completed_jobs: completed,
|
||||
remaining_jobs: remaining,
|
||||
skipped_jobs: skipped.length,
|
||||
skipped_completed_jobs: skipped.length,
|
||||
resumed: Boolean(resume && (hadManifest || skipped.length > 0)),
|
||||
active_jobs: [...active.values()].map(j => ({ name: j.name, start: j.start, limit: j.limit })),
|
||||
failed_jobs: failed.map(j => ({ name: j.name, code: j.code, log: j.log }))
|
||||
}, null, 2)}\n`, 'utf8')
|
||||
}
|
||||
await writeProgress(jobs.length ? 'running' : 'done')
|
||||
|
||||
async function worker(slot) {
|
||||
while (next < jobs.length) {
|
||||
const job = jobs[next++]
|
||||
if (await completedJob(job)) {
|
||||
skipped.push(job)
|
||||
done.push({ ...job, code: 0, skipped: true })
|
||||
process.stderr.write(`[swarm:${slot}] skip ${job.name} (resume)\n`)
|
||||
await writeProgress('running')
|
||||
continue
|
||||
}
|
||||
await fs.writeFile(job.shardGraph, '{"nodes":[],"links":[]}\n', 'utf8')
|
||||
active.set(job.name, job)
|
||||
process.stderr.write(`[swarm:${slot}] start ${job.name}\n`)
|
||||
await writeProgress('running')
|
||||
const result = await runWorker({ ...job, graph: job.shardGraph })
|
||||
active.delete(job.name)
|
||||
done.push(result)
|
||||
if (result.code === 0) {
|
||||
await fs.writeFile(job.done, `${JSON.stringify({
|
||||
name: job.name,
|
||||
signature: job.signature,
|
||||
graph: job.shardGraph,
|
||||
log: job.log,
|
||||
finished_at: new Date().toISOString()
|
||||
}, null, 2)}\n`, 'utf8')
|
||||
}
|
||||
process.stderr.write(`[swarm:${slot}] done ${job.name} code=${result.code}\n`)
|
||||
await writeProgress('running')
|
||||
}
|
||||
}
|
||||
await Promise.all(Array.from({ length: Math.min(concurrency, jobs.length) }, (_, i) => worker(i + 1)))
|
||||
@@ -144,17 +234,26 @@ async function main() {
|
||||
graph,
|
||||
shards_dir: shardsDir,
|
||||
manifest: manifestPath,
|
||||
progress: progressPath,
|
||||
total,
|
||||
selected: limit,
|
||||
selected,
|
||||
start,
|
||||
chunk_size: chunkSize,
|
||||
batch_size: batchSize,
|
||||
excerpt_chars: excerptChars,
|
||||
max_tokens: maxTokens,
|
||||
backend: backend || null,
|
||||
model: model || null,
|
||||
cache_dir: cacheDir,
|
||||
cache,
|
||||
resume,
|
||||
resumed: Boolean(resume && (hadManifest || skipped.length > 0)),
|
||||
concurrency,
|
||||
completed: done.length,
|
||||
skipped: skipped.length,
|
||||
failed: failed.map(j => ({ name: j.name, start: j.start, limit: j.limit, log: j.log }))
|
||||
}, null, 2))
|
||||
await writeProgress(failed.length ? 'failed' : 'done')
|
||||
if (failed.length) process.exit(1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user