/** * state.ts — Manages the lockfile (`.doc-lok/lock.json`) that persists * per-URL cryptographic metadata so unchanged remote resources can be * skipped. All doc-lok artifacts live under the `.doc-lok/` directory * so the project root stays clean. */ /** Metadata tracked for every URL seen by doc-lok. */ export interface UrlEntry { /** Last computed SHA-256 hex digest of the response body. */ last_known_sha256: string; /** HTTP ETag returned by the server, if any. */ etag: string | null; /** Approximate token cost of the raw (un-condensed) content. */ token_cost_raw: number; /** Token cost after condensing (the HTML comment marker). */ token_cost_compressed: number; /** ISO-8601 timestamp of the last successful validation. */ last_checked: string; /** True once this URL has been successfully cached/condensed for the first time. * Used to prevent double-counting token savings in global_tokens_saved. * Absent in legacy lockfiles — treated as false on first read. */ cached?: boolean; /** Original anchor text from the inline link, stored so restore can * reconstruct `[text](url)` instead of `[url](url)`. Only present when the * anchor text differs from the URL. */ original_text?: string; /** True once the body has been converted to Markdown + section-indexed. * Added in lockfile v3. Absent on v1/v2 lockfiles, treated as false. */ converted?: boolean; /** Slugs of sections detected from the converted Markdown. * Informational only — the cache files (.md + .index.json) are the * source of truth for content. Added in lockfile v3. */ section_slugs?: string[]; } /** Top-level lockfile shape. */ export interface Lockfile { /** Schema version for forward compatibility. */ version: number; /** Running global tally of tokens saved across all runs. */ global_tokens_saved: number; /** Per-URL metadata keyed by canonical URL string. */ urls: Record; } /** Rough tokens-per-character heuristic (≈4 chars/token for English text). */ export declare const CHARS_PER_TOKEN = 4; /** The condensed marker occupies ~18 tokens including delimiters (now includes a 6-char URL hash). */ export declare const COMPRESSED_MARKER_TOKENS = 18; /** * Resolve the lockfile path. Resolution order: * 1. Explicit `lockfilePath` argument. * 2. `DOC_LOK_LOCKFILE` env var. * 3. `.doc-lok/lock.json` in the same directory as the Markdown file. * 4. `.doc-lok/lock.json` in `process.cwd()`. * * All doc-lok runtime artifacts (lockfile, cache) live under a single * `.doc-lok/` directory so the project root stays clean. */ export declare function resolveLockfilePath(mdFilePath: string, lockfilePath?: string): string; /** Read and parse the lockfile, returning a default skeleton if absent. */ export declare function readLockfile(lockfilePath: string): Promise; /** Atomically write the lockfile to disk (write-temp-then-rename). */ export declare function writeLockfile(lockfilePath: string, data: Lockfile): Promise; /** Estimate token count from a string length. */ export declare function estimateTokens(text: string): number; /** * Compute a stable hash of a URL for marker embedding. * Returns the full 64-character SHA-256 hex digest. * * The full digest makes marker collisions astronomically unlikely * (birthday bound at ~2^128 URLs) so `--restore` and `--inline` * never silently substitute the wrong URL or content. */ export declare function hashUrl(url: string): string; /** Record a successful validation result against a lockfile entry. * * @param isUnchanged Whether the remote content is unchanged since last run. * When true, tokensSaved is 0 (already counted). * When false, tokensSaved reflects first-time savings. */ export declare function updateEntry(lockfile: Lockfile, url: string, sha256: string, etag: string | null, rawTokenCost: number, isUnchanged: boolean): { entry: UrlEntry; tokensSaved: number; }; //# sourceMappingURL=state.d.ts.map