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

59 lines (58 loc) • 2.55 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/. /** * Shared `entries`-row projection + mapper for the `index.db` storage repos. * * Centralizes the one canonical `entries` SELECT column list and the * JSON-parse-guarded row → {@link DbIndexedEntry} mapping shared by several queries. Corrupt `document_json` rows are skipped (warn once) rather * than crashing the caller. * * It imports the shared shapes from the leaf types module * `./index-entry-types.ts` rather than reaching across the storage↔indexer * boundary, so it does not join an import cycle. */ import { warn } from "../../core/warn.js"; /** * Canonical column list for reading a full indexed entry from the `entries` * table, in the order {@link rowToIndexedEntry} expects. * * Durable identity columns are surfaced here so every mapped entry carries * current indexed provenance. */ export const ENTRY_COLUMNS = "id, item_ref, bundle_id, concept_id, adapter_id, type, file_path, content_hash, document_json"; /** * The path a row stores for an asset no file holds: none. A row written before 4f.2 keyed such an asset under a path * inside its bundle's root and marked its document `fileless`; until `akm migrate apply` re-keys it, that row is read * as the row with no file it stands for, so no command notices the difference. Removed in 0.11 with the migration step. */ export function storedFilePath(filePath, document) { // asset-io: deprecated a layout-26 row from before 4f.2, read until `akm migrate apply` re-keys it return document?.fileless === true ? "" : filePath; } /** * Map one raw `entries` row to a {@link DbIndexedEntry}, parsing `document_json`. * Returns `null` (and warns, tagged with `context`) when the JSON is corrupt so * callers can skip the row instead of crashing. */ export function rowToIndexedEntry(row, context) { let entry; try { entry = JSON.parse(row.document_json); } catch { warn(`[db] ${context}: skipping entry id=${row.id} — corrupt document_json`); return null; } return { id: row.id, filePath: storedFilePath(row.file_path, entry), entry, itemRef: row.item_ref, conceptId: row.concept_id, bundleId: row.bundle_id, adapterId: row.adapter_id, type: row.type, ...(row.content_hash ? { contentHash: row.content_hash } : {}), }; }