/**
 * `GET /api/source?file=&from=&to=` — verbatim source, or an honest refusal.
 *
 * This is the one endpoint that reads the user's repository, so two rules
 * govern it and neither is negotiable.
 *
 * **Every read goes through `resolveProjectFile`.** That is the chokepoint from
 * `security.ts` — traversal, in-tree symlinks pointing out of the root,
 * absolute paths, sensitive system directories. Without it,
 * `?file=../../.ssh/id_rsa` is a credential leak over a port the user opened to
 * read their own code.
 *
 * **A file that changed on disk since it was indexed is never sliced under the
 * index's numbering.** The viewer asks for line ranges the *index* recorded; if
 * the file moved on since, those ranges can point at a different symbol's body,
 * which would be served under the requested name and look perfectly plausible.
 * So the bytes are hashed and compared against `files.content_hash`, and on a
 * mismatch the slice is omitted with `drift: true` — the same call
 * `codegraph_node` makes when it says "changed on disk after the last index
 * sync".
 *
 * A caller that has ALREADY decided the index's numbering is off — a viewer
 * about to draw a drift banner — asks with `ondrift=current` and gets the
 * file's CURRENT lines instead of nothing. That is the other half of
 * `codegraph_node`'s behaviour (issue #1474): a drifted file is served whole
 * and current rather than omitted, because current bytes are correct by
 * construction. `showing` says which of the two came back, on every response,
 * so nothing has to infer it from the presence of `lines`.
 *
 * Only files that are IN the index are served. That is a tighter boundary than
 * the MCP tools take, and it costs the viewer nothing (it only ever renders
 * indexed symbols) while making the drift verdict meaningful for every answer:
 * there is always a hash to compare against.
 */
import type { FileRecord } from '../../types';
import type { CodeGraph } from '../../index';
import { type HighlightResult } from '../highlight';
import { ApiError } from './respond';
/**
 * Largest file we will read to answer a source request.
 *
 * The whole file has to be read to hash it, so this bounds the work one request
 * can cause. Well above the 1 MB ceiling extraction itself applies, so anything
 * actually in the index is comfortably inside it.
 */
export declare const MAX_SOURCE_BYTES: number;
/** Lines returned in one response. The Symbol view asks for windows, not files. */
export declare const MAX_SOURCE_LINES = 4000;
/**
 * Look up a file record by a viewer-supplied path, WITHOUT validating it.
 *
 * Indexed paths are normalized to forward slashes at extraction time, so that
 * is the form tried first; the platform-separator form is a fallback for an
 * index written before that normalization.
 *
 * Callers that go on to READ the file must use {@link resolveRequestedFile}
 * instead — it puts the path through the security chokepoint first. This one is
 * for endpoints that only need the record (a drift flag on a path the index
 * itself handed us).
 */
export declare function findIndexedFile(cg: CodeGraph, requested: string): {
    record: FileRecord;
    storedPath: string;
} | null;
/**
 * Forward slashes and no leading `./` — the form indexed paths are stored in.
 *
 * A LEADING SLASH IS LEFT ALONE on purpose. Stripping it would quietly turn
 * `/etc/passwd` into the project-relative `etc/passwd` and answer "not in this
 * index" — reinterpreting the request instead of refusing it, and leaving the
 * chokepoint's absolute-path rule with nothing to catch.
 */
export declare function toRequestPath(requested: string): string;
/**
 * Validate a viewer-supplied path, THEN look it up in the index.
 *
 * The order is the point. `resolveProjectFile` runs first, so a traversal, an
 * absolute path or a sensitive system directory is refused as what it is,
 * before the index is consulted — a 403 that says "outside the project", not a
 * 404 that says "not indexed" and quietly depends on the index lookup missing.
 * It also means the absolute path every reader uses has already been through
 * the chokepoint by construction, rather than by remembering to call it.
 *
 * @throws {PathRefusalError} the path is not one we would ever read.
 * @throws {ApiError} `not-found` when it is fine but not in the index.
 */
export declare function resolveRequestedFile(cg: CodeGraph, projectRoot: string, requested: string): {
    record: FileRecord;
    storedPath: string;
    absolute: string;
};
export declare function notIndexedError(file: string): ApiError;
/**
 * Split source the way the index counted it.
 *
 * Rows are `\n`-delimited — that is how tree-sitter numbers them — so a CRLF
 * file has the same line numbers here as in the graph. The trailing `\r` is
 * dropped per line so it does not render as a stray glyph.
 */
export declare function splitLines(content: string): string[];
/**
 * The whole text of an INDEXED file, or `null` for anything unreadable.
 *
 * The dead code report's corroboration pass needs to count an identifier in a
 * file's text, and this module is the only one in `api/` that opens a file — so
 * the reader it uses lives here, behind the same chokepoint. Three refusals,
 * all answering `null` rather than throwing, because the caller's rule is
 * already "cannot read it → do not make the claim":
 *
 * - not in the index (the viewer never reads a file the graph does not know);
 * - outside the project (`resolveProjectFile` throws; caught here);
 * - bigger than `maxBytes`.
 *
 * Drift is deliberately NOT checked. The question being asked is "does anything
 * in this file write this name", and the file's current bytes are the better
 * answer to it than the bytes we indexed.
 */
export declare function readIndexedFileText(cg: CodeGraph, projectRoot: string, requested: string, maxBytes: number): string | null;
/**
 * Whether an indexed file has changed on disk since it was indexed — the same
 * verdict `/api/source` returns, for endpoints that must *flag* drift without
 * serving source (a symbol header, a file outline).
 *
 * Cheap first: size plus floored mtime is the identical freshness test the sync
 * fast path uses, so an untouched file costs one `stat`. Only a stat mismatch
 * pays for a hash, which is what keeps a `touch` or a checkout that rewrote
 * identical bytes from reading as drift.
 *
 * Any failure answers `false`. A wrong "stale" flag would put a warning banner
 * over correct source; the cases that would trip it (missing record, unreadable
 * file) have their own handling in the endpoints that actually read.
 */
export declare function hasDriftedOnDisk(projectRoot: string, storedPath: string, record: FileRecord): boolean;
/**
 * The drift verdict AND the file's length, from one read.
 *
 * The whole-file view needs both before it draws anything: the drift banner,
 * and the line count that fixes the height of the scrolling document (every
 * line is a fixed 20px, so the total IS the layout). Asking
 * {@link hasDriftedOnDisk} and then a source page would answer the first
 * question against one read of the file and the second against another, which
 * is exactly the window in which a file can change underneath the two.
 *
 * Unlike `hasDriftedOnDisk` there is no stat-only fast path: the bytes have to
 * be read to be counted. That is the cost of knowing the length, and it is
 * bounded by {@link MAX_SOURCE_BYTES} like every other read here.
 */
export declare function readFileShape(projectRoot: string, storedPath: string, record: FileRecord): {
    drift: boolean;
    totalLines: number | null;
    reason?: string;
};
export interface SourceResult {
    file: string;
    language: string;
    /** The file on disk differs from what was indexed. */
    drift: boolean;
    /**
     * Which numbering the returned lines belong to.
     *
     * `'indexed'` — the file matches the index, so the two are the same thing.
     * `'current'` — the file drifted and the caller asked for it anyway
     * (`ondrift=current`): these are the bytes on disk right now, and NOTHING the
     * graph holds about this file (symbol ranges, call-site lines, ports) lines
     * up with them.
     * `'none'` — the file drifted and no slice is served.
     */
    showing: 'indexed' | 'current' | 'none';
    contentHash: string;
    indexedAt: number;
    generated: boolean;
    totalLines: number | null;
    from?: number;
    to?: number;
    lines?: string[];
    truncated?: boolean;
    reason?: string;
    /**
     * The same lines, classified for the code block — one entry per line, each a
     * list of `[classId, text]` pairs indexed into `highlight.classes`.
     *
     * It rides with the slice rather than living behind its own endpoint because
     * the two are only ever wanted together, and because a second round-trip
     * would let the viewer paint unhighlighted source and then reflow it. Absent
     * whenever `lines` is — a drifted file is not served at all.
     */
    highlight?: HighlightResult;
}
/**
 * What to do when the file on disk no longer matches the index.
 *
 * `omit` (the default) is the safe answer for a caller that has not decided
 * anything yet. `current` is for one that has: it is about to say, in the
 * pixels, that these are the file's CURRENT lines and that nothing the graph
 * holds about them applies.
 */
export type OnDrift = 'omit' | 'current';
export declare function parseOnDrift(query: URLSearchParams): OnDrift;
export declare function buildSource(cg: CodeGraph, projectRoot: string, query: URLSearchParams): Promise<SourceResult>;
//# sourceMappingURL=source.d.ts.map