/** * Shared helper functions and types for Dossier CLI commands. * Extracted from the monolithic bin/dossier entry point. */ import { RECOMMENDED_FIELDS, REQUIRED_FIELDS, VALID_RISK_LEVELS, VALID_STATUSES } from '@ai-dossier/core'; /** Root of the CLI package (cli/) */ export declare const CLI_ROOT: string; /** The bin/ directory */ export declare const BIN_DIR: string; /** Official KMS keys that require CI/CD signing (not direct CLI use) */ export declare const OFFICIAL_KMS_KEYS: string[]; export { RECOMMENDED_FIELDS, REQUIRED_FIELDS, VALID_RISK_LEVELS, VALID_STATUSES }; /** Maximum results per page for CLI pagination commands. */ export declare const MAX_PER_PAGE = 1000; export interface VerificationOptions { skipChecksum?: boolean; skipAllChecks?: boolean; force?: boolean; noPrompt?: boolean; } export interface VerificationStage { stage: number; name: string; passed?: boolean; skipped?: boolean; } export interface VerificationResult { passed: boolean; stages: VerificationStage[]; } export interface ListSource { type: 'local' | 'github'; path?: string; owner?: string; repo?: string; branch?: string; } export interface DossierMetadata { path: string; filename: string; title: string; version?: string; risk_level?: string; category?: string; status?: string; signed?: boolean; checksum?: boolean; objective?: string; error: string | null; } export interface GitHubFile { path: string; rawUrl: string; githubUrl: string; } /** * Validate that a path is relative and contains no ".." traversal. * @throws Error if the path is absolute or contains path traversal. */ export declare function validateRelativePath(filePath: string): void; /** * Parse and clamp pagination options from CLI string arguments. * Logs a warning when values are clamped. */ export declare function parsePaginationParams(pageStr: string | undefined, perPageStr: string | undefined, defaults?: { page: number; perPage: number; }): { page: number; perPage: number; }; /** * Validate a dossier name to prevent path traversal attacks. * Rejects names containing '..' segments or absolute paths. * @throws Error if the name is invalid. */ export declare function validateDossierName(name: string): void; /** * Safely join a base directory with a dossier name and verify the result * stays within the base directory. * @throws Error if the resolved path escapes the base directory. */ export declare function safeDossierPath(baseDir: string, dossierName: string): string; /** * Read all data from stdin (piped input) with a timeout. * Returns null if stdin is a TTY (interactive terminal). */ export declare function readStdin(timeoutMs?: number): Promise; /** * Detect whether we're already running inside an interactive agent session * (Claude Code or opencode), identified by the session env var each sets. * When nested, `run` should hand the dossier content back to the calling * session instead of spawning a new LLM subprocess. * @returns The host's display name, or null if not nested. */ export declare function detectNestedHost(): string | null; /** * Detect and resolve which LLM to use. * @returns The resolved LLM name, or null if none detected. */ export declare function detectLlm(llmOption: string, silent?: boolean): string | null; export interface LlmExecDescriptor { cmd: string; args: string[]; /** If set, pipe this content to the process's stdin */ stdin?: string; /** Human-readable description for logging */ description: string; } /** * Passthrough options forwarded to the underlying LLM CLI (claude-code). * These map to claude flags; most only apply in headless (`-p`) mode. */ export interface LlmPassthroughOptions { model?: string; /** USD budget; forwarded as `--max-budget-usd` (headless only). */ budget?: number; permissionMode?: string; /** Raw list from the CLI (space- or comma-separated); normalized to commas. */ allowedTools?: string; } /** * Download a URL to a local temp file (synchronous). * Returns the temp file path. */ export declare function downloadUrlToTempFile(url: string): string; /** * Build the execution descriptor for a given LLM. * File must be a local file path (download URLs first with downloadUrlToTempFile). * @returns The execution descriptor, or null for unknown LLM. */ export declare function buildLlmCommand(llm: string, file: string, headless?: boolean, passthrough?: LlmPassthroughOptions): LlmExecDescriptor | null; /** * Multi-stage verification pipeline. */ export declare function runVerification(file: string, options: VerificationOptions): Promise; /** * Recursively find all .ds.md files in a local directory. */ export declare function findDossierFilesLocal(dir: string, recursive?: boolean): string[]; /** * Parse source string to determine type and details. */ export declare function parseListSource(source: string): ListSource; /** * Fetch GitHub repository tree and find .ds.md files. */ export declare function findDossierFilesGitHub(owner: string, repo: string, subpath: string, branch: string): Promise; /** * Fetch and parse dossier metadata from a URL. */ export declare function fetchDossierMetadata(url: string, displayPath: string): Promise; /** * Parse dossier metadata from file content. */ export declare function parseDossierMetadataFromContent(content: string, filePath: string): DossierMetadata; /** * Parse dossier metadata from a local file. */ export declare function parseDossierMetadataLocal(filePath: string): DossierMetadata; /** * Verify a dossier file (quick check using the TS module directly). */ export declare function verifyDossierQuick(filePath: string): Promise; /** * Format output as table. */ export declare function formatTable(dossiers: DossierMetadata[], showPath?: boolean): string; /** * Print registry errors to stderr in a consistent format. * Used across commands when multi-registry lookups partially or fully fail. */ export declare function printRegistryErrors(errors: ReadonlyArray<{ registry: string; error: string; }>, style?: 'indent' | 'warning'): void; /** * Classify and print a user-facing error when all registries fail to resolve a dossier. * Distinguishes between 404s, timeouts, mixed failures, and other errors. */ export declare function printRegistryNotFoundError(label: string, errors: ReadonlyArray<{ registry: string; error: string; }>): void; /** * Extract and format common dossier display fields from a registry list item. * Used by search and list commands to normalize metadata for display. */ export declare function formatDossierFields(d: { name?: string; version?: string; title?: string; category?: string | string[]; description?: string; objective?: string; }): { name: string; version: string; title: string; category: string; description: string; }; /** * Log pagination info to the console. * Used by search and list commands when results span multiple pages. */ export declare function logPaginationInfo(total: number, page: number, perPage: number): void; //# sourceMappingURL=helpers.d.ts.map