import { DocumentId } from '../../../platform/inlineEdits/common/dataTypes/documentId'; import { LanguageContextResponse } from '../../../platform/inlineEdits/common/dataTypes/languageContext'; import * as xtabPromptOptions from '../../../platform/inlineEdits/common/dataTypes/xtabPromptOptions'; import { PromptOptions } from '../../../platform/inlineEdits/common/dataTypes/xtabPromptOptions'; import { StatelessNextEditDocument } from '../../../platform/inlineEdits/common/statelessNextEditProvider'; import { IXtabHistoryEntry } from '../../../platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker'; import { OffsetRange } from '../../../util/vs/editor/common/core/ranges/offsetRange'; import { StringText } from '../../../util/vs/editor/common/core/text/abstractText'; import { INeighborFileSnippet } from './similarFilesContextService'; export declare function getRecentCodeSnippets(activeDoc: StatelessNextEditDocument, xtabHistory: readonly IXtabHistoryEntry[], langCtx: LanguageContextResponse | undefined, computeTokens: (code: string) => number, opts: PromptOptions, neighborSnippets?: readonly INeighborFileSnippet[]): { codeSnippets: string; documents: Set; neighborSnippetsResult: AppendNeighborFileSnippetsResult | undefined; subsections: RecentlyViewedSubsectionSnippets; }; /** * Rendered strings for the three sources that make up the * `recently_viewed_code_snippets` block, kept separate so per-subsection token * counts can be reported. Each is the `\n\n`-joined snippets for that source * (empty string when the source contributed nothing). */ export interface RecentlyViewedSubsectionSnippets { readonly recentlyViewedFiles: string; readonly languageContext: string; readonly neighborFiles: string; } export type RecentCodeSnippet = { readonly id: DocumentId; readonly content: StringText; readonly focalRanges?: readonly OffsetRange[]; readonly editEntryCount?: number; }; /** * Build the per-document `RecentCodeSnippet` list that feeds the paged-clipping * recently-viewed builder. Extracted from {@link getRecentCodeSnippets} so the * global-budget cascade can run the recently-viewed sub-builder independently. */ export declare function prepareRecentCodeSnippets(activeDoc: StatelessNextEditDocument, xtabHistory: readonly IXtabHistoryEntry[], opts: PromptOptions): RecentCodeSnippet[]; /** * Select focal ranges prioritizing the most recent (earliest in array order), * capping the total line span to prevent wide-scatter edits from blowing up * the initial page coverage in {@link clipAroundFocalRanges}. * * Focal ranges from {@link historyEntriesToCodeSnippet} are ordered most-recent-first. * When edits are spread across a file (e.g., line 10 + line 90), including all * ranges would cause the initial focal span to cover the entire document. This * function greedily includes ranges until a line span cap is reached. * * @param focalRanges Character-offset ranges ordered most-recent-first. * @param getLineNumber Maps a character offset to a 1-based line number. * @param maxSpanLines Maximum allowed line span for the combined focal range. */ export declare function selectFocalRangesWithinSpanCap(focalRanges: readonly OffsetRange[], getLineNumber: (offset: number) => number, maxSpanLines: number): readonly OffsetRange[]; /** * Convert a group of history entries (all for the same document) into a single code snippet. * Merges focal ranges from all edit entries so clipping can center on all edit locations. * * Focal ranges are only collected from edit entries — visibleRanges entries are skipped * because their character offsets correspond to older document snapshots and cannot be * reliably transformed to the current content's coordinate space. * * For older edit entries, their focal ranges are transformed forward through the chain * of subsequent edits using {@link BaseStringEdit.applyToOffsetRange} so that they * remain valid in the most recent content. */ export declare function historyEntriesToCodeSnippet(entries: IXtabHistoryEntry[]): RecentCodeSnippet; /** * Append language context snippets to the snippets array, respecting the token budget. * Language context snippets omit line numbers because providers do not report source ranges. * * @returns the number of tokens consumed (matches the same per-snippet accounting * the function uses internally for budget decisions). */ export declare function appendLanguageContextSnippets(langCtx: LanguageContextResponse, snippets: string[], tokenBudget: number, computeTokens: (code: string) => number): number; /** * Result of appending neighbor-file snippets, used for telemetry. */ export interface AppendNeighborFileSnippetsResult { /** Total snippets considered (input array length). */ readonly nComputed: number; /** Snippets actually included in the prompt. */ readonly nIncluded: number; /** * Original input indices (ascending) of snippets included in the prompt. * E.g. `[3, 4, 6]` means snippets at original indices 3, 4 and 6 were included * (snippet at index 5 was skipped — too large or duplicate doc — and snippets * at 0, 1 and 2 were skipped because the budget ran out). */ readonly includedIndices: readonly number[]; /** Tokens consumed using the same per-snippet accounting used for budget decisions. */ readonly tokensConsumed: number; } /** * Append Completions-style neighbor-file snippets (Jaccard-ranked) to the snippets array. * * Snippets are pre-clipped by Completions (each is a fixed-window match around * the cursor in a neighbor file) and arrive ordered with the highest-scoring * snippet last. We select greedily from highest score downward so the best * snippets reserve budget first, skipping any whose file is already represented * in {@link docsInPrompt} (avoids duplicating recently-edited or recently-viewed * files) and any snippet that would exceed the remaining token budget. Selected * snippets are then appended in score-ascending order so the highest-scoring * snippet ends up closest to the current file in the prompt. */ export declare function appendNeighborFileSnippets(neighborSnippets: readonly INeighborFileSnippet[], snippets: string[], docsInPrompt: Set, tokenBudget: number, computeTokens: (code: string) => number, includeLineNumbers: xtabPromptOptions.IncludeLineNumbersOption): AppendNeighborFileSnippetsResult; /** * Compute the token cost of the focal pages for a file — the minimum tokens * needed to include just the pages that contain the focal ranges. * * Returns `undefined` when there are no usable focal ranges. */ export declare function computeFocalPageCost(content: StringText, focalRanges: readonly OffsetRange[], pageSize: number, computeTokens: (s: string) => number): number | undefined; /** * Build code snippets using paged clipping. * * @param recentlyViewedCodeSnippets List of recently viewed code snippets from most to least recent */ export declare function buildCodeSnippetsUsingPagedClipping(recentlyViewedCodeSnippets: RecentCodeSnippet[], computeTokens: (s: string) => number, opts: PromptOptions): { snippets: string[]; docsInPrompt: Set; tokensConsumed: number; }; //# sourceMappingURL=recentFilesForPrompt.d.ts.map