Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697/** Positional OCR input loading boundary. @module */
import { readStructuredInputFile, } from './file-input.ts';import type { CliInputArgument, } from './cli-input.ts';import { parseStructuredInput, } from './ingest.ts';import type { NormalizedInput, } from './model.ts';
/** Reports positional value that is neither inline JSON nor an existing file. */export class CliInputNotFoundError extends Error { /** Creates unavailable-input failure without reading standard input. @param input - Positional value interpreted as named path. @param cause - Filesystem evidence proving path absence. @example ```ts new CliInputNotFoundError({ input: 'review.json', cause: new Error('missing') }); ``` */ public constructor({ input, cause, }: { readonly input: string; readonly cause: unknown; },) { super( `positional input ${JSON.stringify(input,)} is neither inline JSON nor an existing named file`, { cause, }, ); this.name = 'CliInputNotFoundError'; }}
/** Node filesystem error shape carrying operation code. */type NodeFileError = Error & { readonly code?: unknown;};
/** Detects absent named-file evidence. @param value - Caught filesystem value. @returns Whether Node reported `ENOENT`. */function isAbsentFileError(value: unknown,): value is NodeFileError { return (Error.isError(value,)) && ((value as NodeFileError).code === 'ENOENT');}
/** Loads shell-quoted inline JSON or required named file. @param input - Validated positional input union. @returns Atomically normalized OCR input. @throws {@link CliInputNotFoundError} when named path does not exist. @example ```ts await loadCliInput({ input: { kind: 'file', path: 'review.json' } }); ``` */export async function loadCliInput({ input,}: { readonly input: CliInputArgument;},): Promise<NormalizedInput> { if (input.kind === 'inline-json') { return parseStructuredInput({ text: input.text, },); } try { return await readStructuredInputFile({ path: input.path, }); } catch (error: unknown) { if (isAbsentFileError(error,)) { throw new CliInputNotFoundError({ input: input.path, cause: error, },); } throw error; }}