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

36 lines (35 loc) • 1.92 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/. /** * One-time carry-over of the refs of files that sit outside their type's folder. * * Releases before path refs gave such a file the ref `<type folder>/<its path>` * (`reports/x.md` was `knowledge/reports/x`); its ref is now its path * (`reports/x`). The mapping is closed-form, so each indexed entry names the old * ref its history is stored under, and the rows keyed by it are re-keyed in * place: the `entries` row (keeping its id, which keeps its usage events and * scores attached) and the ref-keyed state.db rows (`rekeyStateRefs`). Idempotent: once the rows * carry the new ref there is nothing under the old one. */ import { stashDirFor } from "../core/asset/asset-placement.js"; /** The ref releases before path refs gave this entry, or `undefined` when its ref never changed. */ export function legacyRefMove(bundleId, type, conceptId) { const dir = stashDirFor(type); if (dir === undefined || conceptId.startsWith(`${dir}/`)) return undefined; return { oldItemRef: `${bundleId}//${dir}/${conceptId}`, newItemRef: `${bundleId}//${conceptId}` }; } /** Re-key the `entries` row the old ref names, in place, when the same file holds it. Returns whether one moved. */ export function rekeyLegacyEntry(db, move, conceptId, filePath) { const old = db .prepare("SELECT id FROM entries WHERE item_ref = ? AND file_path = ?") .get(move.oldItemRef, filePath); if (!old) return false; const stale = db.prepare("SELECT id FROM entries WHERE item_ref = ?").get(move.newItemRef); if (stale) return false; db.prepare("UPDATE entries SET item_ref = ?, concept_id = ? WHERE id = ?").run(move.newItemRef, conceptId, old.id); return true; }