import type { ContextSessionDelta, ContextSessionDiagnostics, ContextSessionState } from '../contracts/context-session.js'; /** * #80 — cache-aware prompt layout: order stable_sections so the most stable * content (workspace manifest, language summary) sits first and the most * task-volatile content (current question, recent changes) sits last. The * compiler sorts on `sort_key ?? ref`; recommended sort_key prefixes: * * "01_workspace_*" — repository manifest, language summary (most stable) * "10_communities_*" — community / structure overview (semi-stable) * "20_evidence_*" — task-relevant evidence (semi-stable; rebuilds when * anchor changes but stays stable across follow-ups * in the same session) * "90_anchor_*" — current task anchor (least stable; emits last) * * The stable_prefix is byte-stable when the underlying graph + anchor are * unchanged across follow-ups, so Anthropic's automatic prompt cache can * reuse the entire prefix. */ export interface ContextPromptStableSection { ref: string; title?: string; body: string; sort_key?: string; } export interface ContextPromptDynamicSection { title?: string; body: string; } export interface BuildContextPromptInput { instructions: readonly string[]; stable_sections: readonly ContextPromptStableSection[]; dynamic_sections: readonly ContextPromptDynamicSection[]; stable_prefix_title?: string; session?: ContextSessionState; } export interface ContextPromptMetrics { raw_prompt_tokens: number; stable_prefix_tokens: number; dynamic_suffix_tokens: number; session_payload_tokens: number; effective_prompt_tokens: number; reused_context_tokens: number; } export interface BuiltContextPrompt { prompt: string; stable_prefix: string; dynamic_suffix: string; session_payload: string; ordered_stable_refs: string[]; session_state: ContextSessionState; session_delta: ContextSessionDelta; session_diagnostics: ContextSessionDiagnostics; metrics: ContextPromptMetrics; /** * #80 (v0.16) — sha256-16 of the stable_prefix. Byte-stable across * runs whenever the underlying graph/anchor are unchanged. Consumers * can compare this hash between runs to verify that Anthropic's * automatic prompt cache will reuse the prefix (cache-aware prompt * layout). When the hash changes, the cache will miss; when it * stays the same, the cache should hit. */ stable_prefix_hash: string; } export declare function buildContextPrompt(input: BuildContextPromptInput): BuiltContextPrompt;