/** * Shared filesystem helpers for adapter session and config I/O. * * Kept intentionally dependency-free — only uses `node:fs/promises` * and `node:path` with forward-slash-safe joins. */ import type { CostRecord, SessionMessage } from '@a5c-ai/comm-adapter'; export declare function findProjectRootSync(startDir?: string): string; export declare function listFilesRecursive(dir: string, predicate: (entryName: string, fullPath: string) => boolean): Promise; /** List *.jsonl files recursively under `dir`. */ export declare function listJsonlFiles(dir: string): Promise; /** List *.json files recursively under `dir`. */ export declare function listJsonFiles(dir: string): Promise; /** * Parse a JSONL file into an array of record objects (ignores blank lines * and lines that fail to parse). Returns empty array if file missing. */ export declare function parseJsonlFile(filePath: string): Promise[]>; /** Read + parse a JSON file. Returns null if missing or invalid. */ export declare function readJsonFile(filePath: string): Promise; /** * Atomically write JSON via the unified core helper (tmp + fsync + rename * with advisory lockfile). Creates parent directories as needed. */ export declare function writeJsonFileAtomic(filePath: string, data: unknown): Promise; /** * Minimal flat-YAML parser for simple `key: value` files. * Supports: * - comments (# ...) * - scalar values (strings, numbers, booleans, null) * - quoted strings ("..." or '...') * - simple nested blocks via two-space indentation (one level deep) * Does NOT support lists, anchors, multi-line strings. */ export declare function parseFlatYaml(text: string): Record; /** Serialize a flat object to simple YAML (top-level + one level of nesting). */ export declare function stringifyFlatYaml(obj: Record): string; /** Atomically write arbitrary text via the unified core helper. */ export declare function writeTextFileAtomic(filePath: string, text: string): Promise; /** fs.stat safely: returns null on ENOENT. */ export declare function statSafe(filePath: string): Promise<{ mtimeMs: number; birthtimeMs: number; size: number; } | null>; /** * Normalize a path to forward slashes (Windows-safe, cross-platform). */ export declare function toPosix(p: string): string; /** * Home-directory-relative join with forward slashes. */ export declare function homeJoin(...segments: string[]): string; /** * Shared `parseSessionFile` logic: read JSONL, derive createdAt from * file stat birthtime, updatedAt from mtime, and build SessionMessage[] * from rows via `rowToMessage` heuristics. * The caller supplies the agent name. */ export declare function parseJsonlSessionFile(filePath: string, agent: string): Promise<{ sessionId: string; agent: string; turnCount: number; createdAt: string; updatedAt: string; messages: SessionMessage[]; raw: unknown; }>; export declare function parseCodexSessionFile(filePath: string, agent: string): Promise<{ sessionId: string; agent: string; turnCount: number; createdAt: string; updatedAt: string; title?: string; model?: string; cost?: CostRecord; cwd?: string; messages: SessionMessage[]; raw: unknown; }>; /** * Derive a SessionMessage-like representation from an arbitrary JSONL row. * Used by adapters that don't have a more precise schema. */ export declare function rowToMessage(row: Record): { role: 'user' | 'assistant' | 'system' | 'tool'; content: string; } | null;