import type { OcrLlmConfig } from '../config/config-types.js'; export type OcrDetectState = 'ready' | 'package-missing' | 'binary-missing' | 'config-missing' | 'detection-failed'; export interface OcrDetectResult { readonly state: OcrDetectState; readonly packageInstalled: boolean; readonly binaryPath: string | null; readonly version: string | null; /** * The peaks-cli config path that holds `peaksConfig.ocr.llm`. * The user pastes the `peaks code-review config-template` output * here. Empty string when peaks-cli has not been bootstrapped. */ readonly configPath: string; readonly configValid: boolean; readonly missingKeys: readonly string[]; readonly warnings: readonly string[]; readonly nextActions: readonly string[]; } export interface OcrReviewInput { readonly projectRoot: string; readonly from?: string; readonly to?: string; readonly commit?: string; } export interface OcrReviewResult { readonly spawned: boolean; readonly state: OcrDetectState; readonly exitCode: number | null; readonly stdout: string; readonly stderr: string; readonly durationMs: number; /** Parsed JSON envelope if the ocr subprocess emitted valid JSON. */ readonly parsed: unknown; readonly warnings: readonly string[]; readonly nextActions: readonly string[]; } export interface SubprocessRunner { run(command: string, args: readonly string[], options: { cwd?: string; timeoutMs: number; env?: NodeJS.ProcessEnv; }): { status: number | null; stdout: string; stderr: string; error?: string; }; } /** * Locate the ocr launcher script (`bin/ocr.js`) inside our own * node_modules tree. Returns null when the npm package is not * present (peaks-cli was installed but its dependency tree is * corrupt, or the user removed it). * * Walks up from this file (dist/src/services/code-review/) to * find the project root, then checks node_modules. */ export declare function resolveOcrLauncher(searchRoots: readonly string[]): string | null; /** * Resolve search roots for the ocr launcher. We look in two * places: (1) the peaks-cli install root (next to our own dist/), * (2) the user's cwd. */ export declare function defaultOcrSearchRoots(currentDirPath: string, cwd: string): readonly string[]; /** * Validate the `peaksConfig.ocr.llm` block the caller (CLI / test) * read out of `~/.peaks/config.json`. Returns the list of missing * required keys (`url`, `authToken`, `model`); empty array means * the block is ready to drive the ocr subprocess. * * The block is independent of the OCR package's own * `~/.opencodereview/config.json` file. peaks-cli only ever reads * from its own config; the env-var injection in `runOcrReview` * makes the legacy file irrelevant. */ export declare function getOcrLlmMissingFields(llm: OcrLlmConfig | null): readonly string[]; /** * Build the env-var overlay peaks-cli injects into the ocr * subprocess. Maps `peaksConfig.ocr.llm` onto the OCR package's * env-var surface (its highest-priority config source). */ export declare function buildOcrEnv(llm: OcrLlmConfig): NodeJS.ProcessEnv; /** * The JSON template the user pastes into their peaks-cli config * (`peaksConfig.ocr.llm`). Returned as a stable string so the * `peaks code-review config-template` CLI command can print it * verbatim, and so the detector's `nextActions` payload embeds * the same shape the user is told to add. */ export declare function getOcrConfigTemplate(): string; export interface OcrDetectOptions { readonly cwd: string; /** * The peaks-cli config path that holds `peaksConfig.ocr.llm`. * Surfaced in the detect result so the user knows where to * paste the template. */ readonly peaksConfigPath: string; /** * The parsed `peaksConfig.ocr.llm` block. `null` when the user * has not yet populated the config; the detector surfaces the * `config-missing` state with a templated `nextActions`. */ readonly peaksOcrConfig: OcrLlmConfig | null; readonly searchRoots?: readonly string[]; readonly runner?: SubprocessRunner; } /** * Detect the full ocr install + config state. The 5 reason states * are unchanged from the soft-optional 2.0.0 contract; only the * source of `config-missing` moved from `~/.opencodereview/config.json` * to `peaksConfig.ocr.llm`. */ export declare function detectOcr(options: OcrDetectOptions): OcrDetectResult; export interface OcrReviewOptions extends OcrDetectOptions { readonly input: OcrReviewInput; } /** * Run ocr review and return the structured result. Detects state * first; soft-fails when ocr isn't ready (the caller — typically * peaks-rd — proceeds without the second-opinion review). * * The LLM endpoint config from `peaksConfig.ocr.llm` is injected * as env vars (`OCR_LLM_URL` / `OCR_LLM_TOKEN` / ...), which the * ocr package treats as the highest-priority config source. This * is how peaks-cli wires the user-managed config into the ocr * subprocess without ever writing `~/.opencodereview/config.json`. */ export declare function runOcrReview(options: OcrReviewOptions): OcrReviewResult;