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

42 lines (41 loc) • 2.04 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/. /** * Belief-state edge writer (#382): append a `supersededBy` edge to an asset's * frontmatter and demote its `beliefState`, metadata only. Idempotent (a * present edge AND demotion is a no-op; an edge without its demotion is * repaired) and never weakens a stronger demotion — severity is * superseded > contradicted > archived. (alpha.4 removed belief weights from * ranking: search no longer reads `beliefState` at all, and `--belief * current|historical` is the only reader, opt-in.) * The SCC resolver in memory-improve.ts is a state-transition writer (it * replaces and clears edges) and deliberately does not use this (#885). */ import { mutateFrontmatter } from "../../../core/asset/frontmatter.js"; /** * An edge value as a list. A scalar string is live data (the indexer accepts * it), so it is promoted rather than dropped on the next write. */ function readEdgeList(value) { if (Array.isArray(value)) return value.filter((v) => typeof v === "string" && v.trim().length > 0); if (typeof value === "string" && value.trim()) return [value.trim()]; return []; } /** Mark an asset superseded by a correction (`akm remember|import --supersedes`). */ export function writeSupersededEdge(filePath, supersededByRef) { mutateFrontmatter(filePath, (parsed) => { const existing = readEdgeList(parsed.data.supersededBy); const currentState = parsed.data.beliefState; const nextState = currentState === "contradicted" || currentState === "archived" ? currentState : "superseded"; if (existing.includes(supersededByRef) && currentState === nextState) return null; return { ...parsed.data, supersededBy: [...new Set([...existing, supersededByRef])].sort(), beliefState: nextState, }; }); }