/** * CLI glue for the `contextatlas index` subcommand (ADR-12). * * Wraps `runExtractionPipeline` with the CLI-specific concerns that * library callers don't need: * - API-key discovery (env var only in v0.1, explicit error if absent) * - Anthropic client construction and retry-wrapper setup * - Adapter lifecycle (spawn, initialize, shutdown on any exit path) * - Summary printing in `key=value` or `--json` shape * - Exit-code mapping per ADR-12 (0 success, 1 extraction failure, 2 setup error) * * Extracted into its own module so `src/index.ts` stays focused on * the dispatcher shape, and so this path is directly testable with a * stubbed Anthropic client. */ import type { ExtractionClient } from "./anthropic-client.js"; import type { ExtractionPipelineResult } from "./pipeline.js"; export interface IndexCliOptions { configRoot: string; configFile: string | null; full: boolean; json: boolean; /** * `--verbose` CLI flag. When true, the run emits per-file * unresolved-token detail to stderr at completion (grouped by * source file, with claim text + frontmatter-vs-claim origin). * Does not affect stdout summary. v0.2 Stream A #3. */ verbose?: boolean; contextatlasVersion: string; /** * Git HEAD SHA of the contextatlas binary itself (atlas schema * v1.3+, v0.3 Theme 1.3). When omitted, the runner resolves it via * `resolveContextatlasCommitSha()` (walks up from this module's * file URL to find package root, then `git rev-parse HEAD`). Tests * pass a string or `null` to bypass git invocation entirely. */ contextatlasCommitSha?: string | null; /** * `--budget-warn ` CLI flag value. When non-null, overrides * `config.extraction.budget_warn_usd`. When null, config value (if * present) takes effect. When both absent, no budget check runs. * v0.2 Stream A #2. */ budgetWarnOverride?: number | null; /** * `--narrow-attribution=` CLI flag value. When non-null, * overrides `config.extraction.narrow_attribution`. When null, * config value (if present) takes effect. When both absent, * baseline frontmatter inheritance (v0.2 behavior) holds. * v0.3 Theme 1.2 Fix 2 (Phase 6 §5.1 muddy-bundle mechanism). */ narrowAttributionOverride?: "drop" | "drop-with-fallback" | null; /** * Test seam — inject a fake ExtractionClient instead of constructing * a real one backed by the Anthropic SDK. When provided, API-key * discovery is skipped AND the post-pipeline `validate-extraction` * auto-invoke (v0.7.1 Step 1.1.b.0 + Q1.1.G.α) is skipped, because * stub clients deliberately produce minimal atlas content that * cannot satisfy realistic per-ADR depth invariants (≥8 claims/ADR). * Production callers always omit; only tests supply. */ clientOverride?: ExtractionClient; /** * Test seam — inject an env-var reader. Defaults to `process.env`. * Lets tests simulate missing keys without mutating the real env. */ readEnv?: (name: string) => string | undefined; /** * Test seam — where summary output goes. Defaults to * `process.stdout.write`. */ writeStdout?: (chunk: string) => void; /** * Test seam — where verbose diagnostic output goes. Defaults to * `process.stderr.write`. Separate from `writeStdout` so tests * can assert on the two channels independently. */ writeStderr?: (chunk: string) => void; } /** * Exit-code contract (ADR-12): per-subcommand semantics. * 0 — success (pipeline ran cleanly, atlas written if modifications) * 1 — extraction failure (pipeline threw, or every document errored) * 2 — setup error (missing API key, config invalid, adapter init failed) */ export type IndexExitCode = 0 | 1 | 2; export interface IndexCliResult { exitCode: IndexExitCode; /** Populated when the pipeline ran to completion (even with per-file errors). */ pipelineResult?: ExtractionPipelineResult; } /** * Run the `index` subcommand end-to-end. Never throws — all error * paths map to exit codes and error messages logged to stderr. */ export declare function runIndexSubcommand(options: IndexCliOptions): Promise; /** * Resolve the contextatlas binary's git HEAD SHA at runtime (atlas * schema v1.3+, v0.3 Theme 1.3). Walks up from this module's file URL * to find the contextatlas package root (the directory containing * `package.json`), then invokes `git rev-parse HEAD` against it. * Returns `null` on any failure path — non-git checkout (e.g., a * published `npm install`-ed binary), `git` not on PATH, or any * other spawn error. Failure is silent: provenance is best-effort, * and absence is a normal state for installed binaries. * * Exported for direct testability; production callers go through * `runIndexSubcommand` which calls this when `contextatlasCommitSha` * is not pre-supplied. */ export declare function resolveContextatlasCommitSha(): string | null; //# sourceMappingURL=cli-runner.d.ts.map