UNPKG

akm-cli

Version:

akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur

69 lines (68 loc) • 3.43 kB
// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. // ── Meta helpers ──────────────────────────────────────────────────────────── export function getMeta(db, key) { const row = db.prepare("SELECT value FROM index_meta WHERE key = ?").get(key); return row?.value; } export function setMeta(db, key, value) { db.prepare("INSERT OR REPLACE INTO index_meta (key, value) VALUES (?, ?)").run(key, value); } /** * Remove a meta key entirely. * * Distinct from writing an empty string: absence is what callers test for * (`getMeta(...) === undefined`), and it is what lets a value be re-derived — * clearing `embeddingDim` after a model change is how the vec table gets * rebuilt at the new width. */ export function deleteMeta(db, key) { db.prepare("DELETE FROM index_meta WHERE key = ?").run(key); } /** What `akm index` found wrong with a keyring's or vault's entries (`akm lint` reports it from here); undefined: never indexed. */ export function getStoreFindings(db, bundleId) { const recorded = getMeta(db, `store-findings:${bundleId}`); return recorded === undefined ? undefined : JSON.parse(recorded); } export function setStoreFindings(db, bundleId, findings) { setMeta(db, `store-findings:${bundleId}`, JSON.stringify(findings)); } // ── Per-directory index state ─────────────────────────────────────────────── export function getIndexDirState(db, dirPath) { const row = db .prepare("SELECT dir_path, file_set_hash, file_mtime_max_ms, reason, updated_at, row_count, index_variant FROM index_dir_state WHERE dir_path = ?") .get(dirPath); if (!row) return undefined; return { dirPath: row.dir_path, fileSetHash: row.file_set_hash, fileMtimeMaxMs: row.file_mtime_max_ms, reason: row.reason, updatedAt: row.updated_at, rowCount: row.row_count ?? undefined, indexVariant: row.index_variant ?? undefined, }; } export function upsertIndexDirState(db, state) { db.prepare(`INSERT INTO index_dir_state (dir_path, file_set_hash, file_mtime_max_ms, reason, updated_at, row_count, index_variant) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(dir_path) DO UPDATE SET file_set_hash = excluded.file_set_hash, file_mtime_max_ms = excluded.file_mtime_max_ms, reason = excluded.reason, updated_at = excluded.updated_at, row_count = excluded.row_count, index_variant = excluded.index_variant`).run(state.dirPath, state.fileSetHash, state.fileMtimeMaxMs, state.reason, new Date().toISOString(), state.rowCount ?? null, state.indexVariant ?? null); } export function deleteIndexDirState(db, dirPath) { db.prepare("DELETE FROM index_dir_state WHERE dir_path = ?").run(dirPath); } /** * The `index_meta` key of the freshness variant the index last scanned `bundle` under: `<adapter id>@<adapter * version>+content<projection version>`. A row an older variant described is described again on its next read. */ export function bundleVariantKey(bundle) { return `variant:${bundle}`; }