/** * Source freshness for the knowledge index. * * `index.db` is a derived cache of the YAML under `.aidlc/knowledge/`, and it used * to be rebuilt only when it was missing or empty. Facts that arrived any other * way — `git pull`, a merge, a branch switch, another worktree's commit — therefore * never reached it, so `aidlc knowledge query` and the `# Codebase Knowledge` block * `aidlc update` writes served whatever state the cache was first built in. Six * instances reverted that block by hand as "unrelated churn"; it was two checkouts * with differently-stale caches disagreeing about the same committed YAML. * * So the index records a fingerprint of the sources it was built from, and * `openKnowledge` rebuilds whenever that record and the disk disagree. * * Two properties are load-bearing, and both come from design DD4 — **every failure * mode here resolves to a rebuild, never to serving stale data**, because forgetting * to record a fingerprint costs one extra rebuild while forgetting to check one costs * a month of wrong facts: * * - The fingerprint is taken *before* the sources are read (AC-7), so a file changed * during the read leaves the record stale and the next open rebuilds. * - A file that cannot be stat-ed hashes to a value no readable tree can produce, * and a different one on each call (AC-5). * * Requirements: knowledge-index-misses-merged-yaml/AC-3, AC-5, AC-7, AC-8 * * @module */ import type { KnowledgeIndex } from './index/knowledge-index.js'; import type { LoadedGraph, YamlSourceStore } from './yaml-source.js'; /** * Stat hash over every YAML source file: path, modification time and size — never * contents. * * Reading every file to decide whether to read every file buys nothing: `loadAll()` * costs 185ms over this repo's 62 source files and this costs 0.99ms, 0.5% of it * (design DD1). The residual risk is a same-millisecond, same-size content change; * only a script produces one, and the only in-process writer updates the index in * the same breath, so the index is already correct when it happens. * * `listSourceFiles()` is already sorted within each half, so the digest needs no * ordering of its own. The path goes into the hash as well as the stats, so adding * or removing a record file changes the fingerprint (AC-3). * * @param source - The YAML store whose files are fingerprinted. * @returns 64 hex characters. */ export declare function fingerprintSources(source: YamlSourceStore): string; /** * Rebuild the index from the YAML sources and record the fingerprint it was built at. * * The only sanctioned way to establish the cache invariant, and the reason it is a * function rather than four lines at each call site: `openKnowledge` and * `knowledge rebuild` both need the same steps in the same order, and spelling that * order out twice is how one of them ends up stamping before it loads (design DD5, * the lesson `AGENT_INFERRED_SOURCE` records in `types.ts`). * * Two callers deliberately do not use it: * * - `knowledge sync` needs the parsed graph in hand to compare against the pre-sync * index before anything is replaced, so it repeats the two steps that matter in the * same order. It is the one site where the ordering can now rot. * - `knowledge compact` passes no fingerprint at all: one would describe files it is * still rewriting. It is left needing one more rebuild, the fail-safe direction. * * @param source - YAML sources, the authority. * @param index - The derived cache to replace. * @returns The parsed graph, warnings included, for the caller to report. */ export declare function rebuildFromSources(source: YamlSourceStore, index: KnowledgeIndex): LoadedGraph; //# sourceMappingURL=source-fingerprint.d.ts.map