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

50 lines (49 loc) • 1.81 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/. /** * The one place lowering notices from several sources become one list. * * Notices are live execution metadata only: executor, report and output paths * merge them, result and evidence journal writers never do. */ import { sortExecutionJson } from "./json.js"; /** * Merge notices in first-seen order, each once. Two notices are the same when * everything about them is, `details` included and key order aside, so two * genuinely different structured diagnostics are not collapsed because their * headline fields match. `undefined` when there are none. */ export function mergeNotices(...groups) { const merged = new Map(); for (const group of groups) { for (const notice of group ?? []) { const key = JSON.stringify(sortExecutionJson(notice)); if (!merged.has(key)) merged.set(key, notice); } } return merged.size > 0 ? Object.freeze([...merged.values()]) : undefined; } const NONE = Object.freeze([]); /** * The notices a run's dispatches report as they go, merged when read. * `forward` also receives each batch as it arrives. */ export function noticeSet(forward) { const groups = []; const add = (notices) => { groups.push(notices); forward?.(notices); }; const list = () => mergeNotices(...groups) ?? NONE; return { add, list, /** `{ notices }` for a result that carries them, `{}` when there are none. */ fields: () => { const notices = mergeNotices(...groups); return notices ? { notices } : {}; }, }; }