@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
54 lines • 2.76 kB
TypeScript
import type { FlagValue } from '../../spec/types.ts';
import { IOResult } from '../../../io/types.ts';
import { type PathSpec, type ReadStreamFn, type StatFn } from '../../../types.ts';
import type { CommandFnResult, Context } from '../../config.ts';
/**
* `-n`/`-c` split by the end they count from. A leading `+` counts forward
* from the start, 1-indexed, so `+0` and `+1` both mean the whole input; any
* other spelling counts back from the end. Mirrors Python's `TailCounts`.
*/
export interface TailCounts {
readonly lines: number | null;
readonly fromLine: number | null;
readonly byteCount: number | null;
readonly fromByte: number | null;
}
/**
* Fill in whatever a caller left off a `TailCounts`.
*
* The struct is a plain object, so a caller that omits a field — or a
* JavaScript one that passes something else entirely — supplies undefined,
* and a bare `!== null` test waves that straight into the first branch,
* where `slice(NaN)` quietly returns the whole input. Python's twin is a
* dataclass whose four fields all default to None and has no such hole;
* reading every field through `?? null` gives this side the same floor.
*/
export declare function normalizeCounts(counts: TailCounts): TailCounts;
/** -f/--follow[=HOW], -F, --retry and -s as tail reads them. */
export interface FollowFlags {
readonly follow: boolean;
readonly byName: boolean;
readonly retry: boolean;
readonly interval: number;
}
export interface TailFlags {
readonly counts: TailCounts;
readonly quiet: boolean;
readonly verbose: boolean;
readonly following: FollowFlags;
}
/**
* tail's options, the values read by mirage-rs before any operand is resolved:
* the flags, or tail's refusal of a value. Mirrors Python's `parse_flags`.
*/
export declare function parseFlags(bag: Record<string, FlagValue>): TailFlags | IOResult;
/**
* Run tail over resolved operands, GNU semantics. A line count from the end
* (`-n N`, or the default 10) is asked of `lastLines` first, so a mount that
* can fetch the end of a file on its own does not send the rest; `-f` on one
* file asks `followOp(p, n, interval)` (see `follow`). Null, or no such op, reads
* or polls the file. Mirrors Python's `tail_generic`; `parsed` holds the
* options, read before the operands were.
*/
export declare function tailGeneric(parsed: TailFlags, paths: PathSpec[], texts: string[], ctx: Context, stream: ReadStreamFn, stat: StatFn, readRange?: ReadStreamFn<[PathSpec, number, number]> | null, lastLines?: (p: PathSpec, n: number) => Promise<Uint8Array | null>, followOp?: (p: PathSpec, n: number, interval: number) => Promise<AsyncIterable<Uint8Array> | null>): Promise<CommandFnResult>;
//# sourceMappingURL=tail.d.ts.map