UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

110 lines (109 loc) • 6.12 kB
import type { RetentionPolicy } from "../shared/governance.js"; export interface FindingCitation { created_at: string; /** The repo's absolute path on the computer that wrote the citation; written now only for a repo with no clone URL. */ repo?: string; /** * The repo by its `origin` remote, as `host/owner/repo` (content/citation-checkouts.ts), * so every computer with a clone of it can check the citation. `file` is then relative to the repo root. */ remote?: string; file?: string; line?: number; commit?: string; /** * A symbol the finding is about, as `Name`, `Type.member` or `name()`. * Auto-attached on write when the project has a code index and the finding * text names exactly one resolvable symbol; an explicit one is validated * against the index and stored either way. */ symbol?: string; /** True when an explicit symbol citation could not be resolved in the index. */ symbol_unresolved?: boolean; supersedes?: string; } export declare const FINDING_PROVENANCE_SOURCES: readonly ["human", "agent", "hook", "extract", "consolidation", "unknown"]; export type FindingProvenanceSource = (typeof FINDING_PROVENANCE_SOURCES)[number]; export declare function isFindingProvenanceSource(value: string | undefined): value is FindingProvenanceSource; export interface FindingProvenance { source?: FindingProvenanceSource; machine?: string; actor?: string; tool?: string; model?: string; session_id?: string; scope?: string; } export interface FindingTrustIssue { date: string; bullet: string; reason: "stale" | "invalid_citation"; } export interface TrustFilterOptions { ttlDays?: number; minConfidence?: number; decay?: Partial<RetentionPolicy["decay"]>; project?: string; highImpactFindingIds?: Set<string>; /** States already known (governance's bounded sweep); an undefined answer counts as unverifiable. Unset checks live. */ citationState?: (citation: FindingCitation, bullet: string) => CitationState | undefined; /** * The citation of a bullet whose comment is not in `content` (the search index strips citation comments), * checked and counted as cited like one on the next line. */ sourceCitation?: (bullet: string) => FindingCitation | undefined; /** The date of an archived bullet from the source file. */ sourceArchiveDate?: (bullet: string) => string | undefined; } export declare function getHeadCommit(cwd: string): string | undefined; export declare function getRepoRoot(cwd: string): string | undefined; export declare function buildCitationComment(citation: FindingCitation): string; /** Format actor/machine attribution for human-readable display. */ export declare function formatActorAttribution(actor: string | undefined, machine: string | undefined): string; export declare function buildSourceComment(source: FindingProvenance): string; /** Build a standalone scope comment. Returns empty string if scope is unset or "shared". */ export declare function buildScopeComment(scope: string | undefined): string; /** Parse a standalone `<!-- scope:VALUE -->` comment. */ export declare function parseScopeComment(line: string): string | undefined; export declare function parseSourceComment(line: string): FindingProvenance | null; export declare function parseCitationComment(line: string): FindingCitation | null; /** Every distinct `symbol:` value in a document's `phren:cite` comments, in order. */ export declare function collectSymbolCitations(content: string): string[]; /** * What this computer can tell about a citation: * - valid: everything it names checks out. * - drifted: the cited line changed since the cited commit, or is past the end of the file; the finding may still be right. * - broken: the repo is here but the cited file is gone. In a checkout other than the one the citation was * written in (found by `remote`, or another computer's repo path relocated here), only when the file was in * the cited commit and that commit is in the checkout's history. * - unverifiable: nothing to check, the repo is not on this computer, git could not run, * or the repo does not know the commit while the file is still there (squash-merged or unfetched). */ export type CitationState = "valid" | "drifted" | "broken" | "unverifiable"; /** Git processes citation checks have started in this process; governance caps a run by it. */ export declare function citationGitCallCount(): number; export interface CitationCheckOptions { /** * The primary store, so a citation's `remote` resolves to this computer's checkout of it. Without it a remote is * unverifiable. Mapping a remote scans folders and may start git, so only the daily sweep passes it; the prompt * hook reads the states the sweep recorded. */ phrenPath?: string; /** * Also look for another computer's absolute repo path among this computer's checkouts with the same folder * name, taking the first that has the cited commit. It costs git calls, so the daily sweep sets it, not the hook. */ relocate?: boolean; } export declare function checkFindingCitation(citation: FindingCitation, opts?: CitationCheckOptions): CitationState; /** False only when this computer knows the citation is broken or its line drifted; one it cannot check passes. */ export declare function validateFindingCitation(citation: FindingCitation, opts?: CitationCheckOptions): boolean; /** How many days a finding bullet lives before it expires: its type's limit in place of the TTL when it * has a type (a decision never expires, a pattern lives a year), else `ttlDays`. The trust filter and * maintenance's TTL review both expire findings by this. */ export declare function findingAgeLimitDays(line: string, ttlDays: number): number; export declare function filterTrustedFindings(content: string, ttlDays: number): string; export declare function filterTrustedFindingsDetailed(content: string, opts: number | TrustFilterOptions): { content: string; issues: FindingTrustIssue[]; };