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

95 lines (94 loc) • 4.03 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/. /** * Valid proposal `source` values (#385): typed sources keep accept-rate per * source aggregatable (PROV-DM). An unknown value is accepted with a warning. */ export const PROPOSAL_SOURCES = [ "reflect", "distill", "consolidate", /** The consolidate pair pass's own retire proposals — kept apart from `consolidate`'s promotions so a bulk `accept --generator consolidate` never sweeps a retirement, and the reverse. */ "consolidate-pair", "extract", "improve", "feedback", "propose", "remember", "import", "distill_quality_rejected", "schema-repair", ]; /** Automated sources, which should carry a `sourceRun`. */ export const AUTOMATED_PROPOSAL_SOURCES = [ "reflect", "distill", "consolidate", "consolidate-pair", "extract", "improve", "schema-repair", ]; export function isValidProposalSource(source) { return PROPOSAL_SOURCES.includes(source); } export function isAutomatedProposalSource(source) { return AUTOMATED_PROPOSAL_SOURCES.includes(source); } /** * The content of a proposal's PRIMARY change. * * By construction `changes[0].content === payload.content` for a `create` or `update` change; consumers read through * this accessor so the single-content assumption lives in ONE place. A `delete` primary change (a consolidate retire * proposal) writes no content by definition, so it reads as `""` rather than throwing: every generic proposal scan * (dedup-by-body-hash, the triage drain's diff-size filter, the quality validators) can call this on ANY pending * proposal, retire included, without special-casing the op first. Typed structurally so this module stays a leaf. */ export function proposalContent(p) { const primary = p.changes[0]; if (primary?.op === "delete") return ""; const content = primary?.content; if (content === undefined) throw new Error("Proposal primary change has no content."); return content; } /** * When a pending proposal's wait for review began: its last reopen (#997), else * its creation. Every age-based sweep — retention expiry, and `--older-than` on * bulk accept/reject and on `drain` — counts from here, so a proposal just put * back in the queue is not swept as if it had been waiting since it was first * created (a scheduled `drain --older-than 7 --promote` would otherwise take * it at once). */ export function proposalWaitingSince(proposal) { return proposal.reviewHistory?.at(-1)?.reopenedAt ?? proposal.createdAt; } /** A pending or accepted proposal whose primary change deletes its target (a consolidate retire proposal). */ export function isRetireProposal(proposal) { return proposal.changes[0]?.op === "delete"; } /** A promote refused because the target changed after mint (STALE, R20) — not a merit judgement. */ export const STALE_TARGET_GATE_REASON = "stale-target"; /** The gate on a retire proposal the triage drain may accept unattended: a staged pair-judged retirement. */ export const PAIR_PASS_GATE = "consolidate-pair"; export const EXPIRED_GATE_REASON = "expired"; export const ASSET_MISSING_GATE_REASON = "asset-missing"; const PROCEDURAL_GATE_REASONS = new Set([ STALE_TARGET_GATE_REASON, EXPIRED_GATE_REASON, ASSET_MISSING_GATE_REASON, ]); /** * A rejection nobody judged on its content (stale target, expiry, orphan * purge). The "previously rejected" prompt context and the accept-rate metric * leave these out. Expiries archived before the gate reason existed are known * by their review reason. */ export function isProceduralRejection(proposal) { if (proposal.gateDecision?.outcome === "auto-rejected" && PROCEDURAL_GATE_REASONS.has(proposal.gateDecision.reason)) { return true; } return proposal.review?.reason?.startsWith("expired:") === true; }