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) • 2.15 kB
JavaScript
// 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/.
const ATTRIBUTION = Symbol("search-hit-attribution");
export function attachSearchHitAttribution(target, attribution) {
const host = target;
host[ATTRIBUTION] = {
...host[ATTRIBUTION],
...attribution,
};
}
export function copySearchHitAttribution(from, to, outputDescription) {
const memoryInference = from[ATTRIBUTION]?.memoryInference;
if (!memoryInference)
return;
const memorySurvives = memoryInference.exposure !== "surface" ||
(memoryInference.surfaceDescription !== undefined && memoryInference.surfaceDescription === outputDescription);
if (memorySurvives)
attachSearchHitAttribution(to, { memoryInference });
}
export function getSearchHitAttribution(target) {
return target[ATTRIBUTION];
}
export function buildUsageEventAttribution(attribution, entryRef, projection = "full") {
const memoryInference = attribution?.memoryInference;
if (!memoryInference)
return undefined;
const childRef = memoryInference.exposure === "direct" ? entryRef : memoryInference.childRef;
const surfaceFields = memoryInference.surfaceFields ?? [];
const surfaceVisible = memoryInference.exposure !== "surface" ||
(projection === "full"
? surfaceFields.length > 0
: projection === "normal" || projection === "agent"
? surfaceFields.includes("description")
: false);
if (childRef?.includes("//") !== true || !surfaceVisible)
return undefined;
return { memoryInference: { exposure: memoryInference.exposure, childRef } };
}
export function usageEventAttributionMetadata(attribution, entryRef, projection = "full") {
const applicable = buildUsageEventAttribution(attribution, entryRef, projection);
return JSON.stringify({
downstreamAttribution: {
version: 1,
control: applicable === undefined,
...applicable,
},
});
}